完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,所以我有一个PIC16F628 A芯片。我可以使用HW UART模块以定制的波特率发送和接收数据。现在我需要在某个时候从另一个PIN发送数据,比如RB5或RB4,以不同的波特率(使用位敲击软件功能——它独立工作良好)。这里的标准是9600波特。问题是当使用软件功能发送数据时,它不能以正确的速度输出。这是因为设置HU-UART参数吗?如果是这样,我该怎么做才能把波特率转换到所需的水平?我试着改变SPBRG的价值,但没什么区别。谢谢。
以上来自于百度翻译 以下为原文 Hi, So I have a PIC16F628A chip. I can send and receive data at a custom baud rate using the HW UART module. Now I need to at some point send data out of another PIN, so like RB5 or RB4 at a different baud rate (using bit banging software functions - which works fine independently ) . Standard 9600 baud here. Problem I have is when using the software functions to send data it doesn't go out at the right speeds. Is this due to setting the HW UART params ? If so what should I do to switch the baud rate to the required level ? I tried to change the value of : SPBRG , but no difference. Thanks |
|
相关推荐
7个回答
|
|
那么你有一个UWART和一个SW UART?这应该有效(并且SPBRG寄存器不会影响SW):显示您的代码位敲击UART…
以上来自于百度翻译 以下为原文 So you have a HW UART and a SW UART? This should work (and SPBRG register won't affect the SW one): show your code for bit-banged UART.... |
|
|
|
你的问题还不清楚,当通过UART的接收激活时,BIT-BANTX定时错误?如果是这样的话,这不是意外的,当交织(UART?)是活跃的。或者禁止在中断期间中断,或者如果可能的话,使用定时中断来获得敲击正时。(我只能希望你不会尝试通过软件接收。)在这种情况下,我建议使用一个PIC与2个或更多UART。
以上来自于百度翻译 以下为原文 Your question is not yet clear.. The bit-bang TX timing is wrong when reception via UART is active? If so: this is not unexpected when interrups (UART?) are active. Either disable interrupts during baning or - if possible - use a timer interrupt to get the banging timing right. (I can only hope you will not try to receive via software. In this case I'd suggest to use a PIC with 2 or more UARTs.) |
|
|
|
对不起,对不起。因此,HW UART(RB1,RB2)以其所需波特率发送和接收到一个设备(设备A)。它很好用。现在对于RB5,RB4我想发送和接收另一波特率通过比特敲击到另一个设备…我本以为位敲击代码应该像不与其他代码绑定时一样工作。没有HW UART...#._XTAL_FREQ 4000000//系统时钟速率define SER_BAUD 103define SER_BIT 1define TxPin PORTBbits.RB5define RxPin PORTBbits.RB4void send_._byte(无符号字符数据){无符号字符i=8;//8个数据位发送到sendTxPin=!SER_BIT;//make start bitTMR0=(256-SER_BAUD);//加载第一波特的TMR1值;.(TMR0&(1<<7));//wait baud.(i)//发送8个串行比特,LSB优先{if(data&1<0)TxPin=SER_BIT;//发送数据比特.TxPin=!data=(data>>1);//右旋转以得到下一位--;TMR0-=SER_BAUD;//负载校正波特值同时(TMR0&;1<;<7);//负载校正波特值同时(TMR0&;1<;<7);;//等待波特}/等待波特}TxPin}TxPin=SER_BIT;//使停止位TMRR0-=SER_BAUD;//使停止位TMR停止位TMRR0-=SER_BAUD;=SER_BAUD;//使停止位TMRR0停止位TMRR0-=SER_BAUD;//停止;//等待两个波特7)TMR0-=SER_BAUD;(TMR0&1<<<7);}无符号char._串_字节(无效){无符号char RxChr(无效){无符号字符RxChr;//无符号字符字符字符Rxchar R无符号char R._._._._seri_._串字节(无效){未签名字符RxChr RxChr RxChr RxChr(RRR0&1&1<1<无效(无效)RXXChr)RXChr);//保持接收到被接收到被接收到字符的串字节的串字节的字符i;//比特索引索引索引索引=8;//比特索引8;//8;//8数据w针对baud.(i)//接收8个串行位,LSB首先{RxChr=(RxChr>>1);//右转以存储每个位(RxPin==1)//保存数据位RxChr=RxChr|SER_BIT<7;否则RxChr=RxChr|!SER_BIT<7;i--//Next BitTMR0-=SER_BAUD;//load.edbaudvalue.(TMR0&1<<7);//wait wait baud}TMR0-=SER_BAUD;//wait等待停止位,确保串行端口是空闲的,同时(TMR0&1<7);在HW UART完成任务后,在主机内返回RxChr;}。要推出pin5@9600.TxPin=0;//Turn all Output OFFTRISBbits.TRISB5=0;TRISBbits.TRISB4=1;OP._REGbits.T0CS=0;//在Timer ModeOP._REGbits.PSA=1中选择TMR0;for(int a=0;a<100;a+){send_._byte(0xAA);u._ms(100);}.(1){}
以上来自于百度翻译 以下为原文 @du00000001 sorry to be clear. So the HW UART (RB1, RB2) are transmitting and receiving to one device (Device A) at its required baud rate. It works fine. Now for RB5, RB4 i want to send and receive at another baud rate via bit banging to another device... i would've thought the bit banging code should just work as it was when not tied in with any other code. @DarioG heres my software bit bang, found online and works at 9600 when just coded as it is... no HW UART... #define _XTAL_FREQ 4000000 // System Clock rate #define SER_BAUD 103 #define SER_BIT 1 #define TxPin PORTBbits.RB5 #define RxPin PORTBbits.RB4 void send_serial_byte(unsigned char data) { unsigned char i; i = 8; // 8 data bits to send TxPin = !SER_BIT; // make start bit TMR0 = (256 - SER_BAUD); // load TMR1 value for first baud; while(TMR0 & (1 << 7)); // wait for baud while(i) // send 8 serial bits, LSB first { if(data & 1<<0)TxPin= SER_BIT; // send data bit else TxPin=!SER_BIT; data = (data >> 1); // rotate right to get next bit i--; TMR0 -= SER_BAUD; // load corrected baud value while(TMR0 & 1<<7); // wait for baud } TxPin = SER_BIT; // make stop bit TMR0 -= SER_BAUD; // wait a couple of baud for safety while(TMR0 & 1<<7); TMR0 -= SER_BAUD; while(TMR0 & 1<<7); } unsigned char receive_serial_byte(void) { unsigned char RxChr; // holds the serial byte that was received unsigned char i; // Bit Index i = 8; // 8 data bits to receive TMR0 =(256 - (SER_BAUD - 19)); // load TMR1 value to offset ~center of RxBit while(TMR0 & 1<<7); // wait for baud while(i) // receive 8 serial bits, LSB first { RxChr = (RxChr>>1); // rotate right to store each bit if( RxPin == 1) // save data bit RxChr = RxChr | SER_BIT<<7; else RxChr = RxChr |!SER_BIT<<7; i--; // Next Bit TMR0 -= SER_BAUD; // load corrected baud value while(TMR0 & 1<<7); // wait for baud } TMR0 -= SER_BAUD; // wait for stop bit, ensure serial port is free while(TMR0 & 1<<7); return RxChr; } inside the main i have this after HW UART has done its things. I want to push out data on pin5 @9600. TxPin = 0; // Turn all Outputs OFF TRISBbits.TRISB5 = 0; TRISBbits.TRISB4 = 1; OPTION_REGbits.T0CS = 0; // Select TMR0 in Timer Mode OPTION_REGbits.PSA = 1; for(int a=0; a<100;a++) { send_serial_byte(0xAA); __delay_ms(100); } while(1) {} |
|
|
|
所以,没有SPBRG,你能看到针脚上的活动吗?波特率是错的吗?你的照片跑的速度是多少?
以上来自于百度翻译 以下为原文 So, no SPBRG, definitely Can you see activity at pins? Is just baud rate wrong? What speed is your PIC running at? |
|
|
|
@DarioGso,这些位正在外出,我可以看到活动,我认为最后两个位,或者时间偏离了某个地方,不知为什么……那么它与HU-UART及其配置无关吗?PIC运行在4MHz。
以上来自于百度翻译 以下为原文 @DarioG so the bits are going out i can see activity, i think the last two bits or the timing is off somewhere and somehow...... so its not related to the HW UART and its config then ? PIC running at 4mhz. |
|
|
|
|
|
|
|
你没有显示任何中断服务例程。如果中断服务占用了10%的时间来发送一个一点一点的BIT,它会破坏你的时序。你最好在3X或4X的软件比特率上运行一个定时器中断,并在那里做你的软件序列。一次只能一点点!你做软件系列的方式相当粗野,容易被其他同时运行的东西打乱。
以上来自于百度翻译 以下为原文 You did not show any interrupt service routine. If the interrupt service takes more say 10% of the time to send one bit by bit-banging, it's going to corrupt your timing. You would be much better off running a timer interrupt at 3x or 4x the software bit rate, and do your software serial in there. Only one bit at a time! The way you are doing software serial is pretty crude, and easily upset by other things running at the same time. |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 11:22 , Processed in 1.375321 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号