完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HALO,根据DSPIC33 EV CAN-LIN套件UART2 TX引脚是RB4。但是,我们总是传递一些垃圾值。很多问题都解决不了。如果我想了什么,请建议。
以上来自于百度翻译 以下为原文 Hallo, according to dsPIC33EV CAN-LIN kit Uart2 TX pin is RB4. But is is alwaya transmitting some garbage values. Tryed a lot bit couldnot solve the problem.Please suggest if i mused something. #include #include "IO.h" #include "UART.h" #include "Timer.h" unsigned char send_buffer1[18]; unsigned char send_buffer2[8]; #define DELAY_105uS asm volatile ("REPEAT, #4201"); Nop(); void UART_init(void) { U2MODEbits.UARTEN = 0; // // digital output TRIS_MON=0; // TRISBbits.TRISB4 = 0; // map MONITOR_TX pin to port RB4, which is remappable RP36 // RPOR1bits.RP36R = 0x03; // map UART2 TXD to pin RB4 // // set up the UART for default baud, 1 start, 1 stop, no parity // U2MODEbits.STSEL = 0; // 1-Stop bit U2MODEbits.PDSEL = 0; // No Parity, 8-Data bits U2MODEbits.ABAUD = 0; // Auto-Baud disabled U2MODEbits.BRGH = 0; // Standard-Speed mode U2BRG = BAUD115200; // Baud Rate setting for 9600 (default) U2STAbits.UTXISEL0 = 0; // Interrupt after TX buffer done U2STAbits.UTXISEL1 = 1; IEC1bits.U2TXIE = 1; // Enable UART TX interrupt IFS1bits.U2TXIF = 0; // Clear TX2 Interrupt flag U2MODEbits.UARTEN = 1; // Enable UART (this bit must be set *BEFORE* UTXEN) U2STAbits.UTXEN = 1; DELAY_105uS } void __attribute__((interrupt, no_auto_psv)) _U2TXInterrupt(void) { //while (U2STAbits.TRMT == 0); // wait for transmitter empty U2TXREG = 'A'; // Transmit one character IFS1bits.U2TXIF = 0; // Clear TX2 Interrupt flag } void Send_POTENTIOMETERInfo(unsigned int count1) { unsigned char tenthousand1 = 0; unsigned char thousand1 = 0; unsigned char hundred1 = 0; unsigned char decimal1 = 0; unsigned char unit1 = 0; tenthousand1= count1 / 10000 + 0x30; thousand1 = count1 % 10000 / 1000 + 0x30; hundred1 = count1 % 1000 / 100 + 0x30; decimal1 = count1 % 100 / 10 + 0x30; unit1 = count1 % 10 + 0x30; send_buffer1[0] = tenthousand1; send_buffer1[1] = thousand1; send_buffer1[2] = hundred1; send_buffer1[3] = decimal1; send_buffer1[4] = unit1; int cnt=0; for(cnt = 0; cnt < 5; cnt++) { U2TXREG= send_buffer1[cnt]; DELAY_105uS } U2TXREG =' '; //send space after each count value // U2TXREG = 0x0A; //keyboard enter after each count value // U2TXREG = 0x0D; //keyboard enter after each count value } #include #include #include #include "Oscillator.h" #include "Delay.h" #include "IO.h" #include "Timer.h" #include "UART.h" #include "ADC.h" int main() { OSC_config(); GPIO_init(); Timer_init(); ADC_init(); UART_init(); int x=1356; while(1) { Send_POTENTIOMETERInfo(x); } return 0; } |
|
相关推荐
7个回答
|
|
定义FCAN 40000000//FCYC=1/2FPLL,定义FoCC 80000000定义BUD115200((FCAN/115200)/16)-1
以上来自于百度翻译 以下为原文 #include #include "IO.h" void OSC_config(void) { // Configure Oscillator to operate the device at 80MHz/40MIPs // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40/(2*2)=80Mhz for 8M input clock // To be safe, always load divisors before feedback CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 PLLFBD = 38; // M=(40-2), Fcyc = 40MHz for ECAN baud timer // Disable Watch Dog Timer RCONbits.SWDTEN = 0; } #define FCAN 40000000 // Fcyc = 1/2Fpll #define FOSC 80000000 #define BAUD115200 ((FCAN/115200)/16) - 1 |
|
|
|
MMMM,如果不使用TX中断,请不要使用TX中断;只使用轮询模式等待TX完成标志,这样比较容易。
以上来自于百度翻译 以下为原文 Mmmm, don't enable TX interrupt if you're not using them; use just polled mode waiting for TX-done flag, it's easier |
|
|
|
啊……我已经做到了,但它并不能解决问题。我仍然在终端窗口获得垃圾值。
以上来自于百度翻译 以下为原文 yah...i have done that, but it doesnot solve the problem. I am still getting garbage value in terminal window. pink: |
|
|
|
你知道ISR不断插入“A”吗?
以上来自于百度翻译 以下为原文 Are you aware that the ISR is constantly inserting 'A's ? |
|
|
|
啊……我知道。但我没有收到A。我正在接受GARBADE……
以上来自于百度翻译 以下为原文 yah....i know. But i am not receiving A. I am receiving garbade...null |
|
|
|
“NULL”(ASCIZ)还是“0”(零)?你的转换代码可以用括号括起来。
以上来自于百度翻译 以下为原文 'Null' (ASCIIZ) or '0' (zeros) ? Your conversion code could do with some bracketing ☺ |
|
|
|
嗨,看起来这个工具包(DSPIC33 EV CAN-LIN)有一个演示文稿,里面包含了UART通信的文档。它可以下载吗?你尝试过了吗?没有任何修改(以确保这是可行的)吗?当做
以上来自于百度翻译 以下为原文 Hi, It seems this kit (dsPIC33EV CAN-LIN) has a demo code explained in the documentation, that contains UART communication. It can be downloaded here Have you tried it without any modification (to make sure this works) ? Regards |
|
|
|
只有小组成员才能发言,加入小组>>
5132 浏览 9 评论
1985 浏览 8 评论
1914 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3153 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2213 浏览 5 评论
702浏览 1评论
593浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
476浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
608浏览 0评论
499浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 10:52 , Processed in 1.347813 second(s), Total 56, Slave 50 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号