完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有一个程序,我只能从UnCuffor发送,但不能接收任何东西。我已经正确地设置了PPS和UART发送数据罚款。但是当我试图在终端上发送任何东西的时候,它似乎并没有得到它。
以上来自于百度翻译 以下为原文 I have a program going and I can only transmit from the uControler, but can't receive anything. I've set the pps correctly and UART send out data fine. But when I try to send anything over the terminal it doesn't seems to be getting it. #include "xc.h" #include "bsp_target.h" #include "bsp_uart.h" #define FCY 60000000 #include #define FW_VER "0.0.1" /******************************************************************************/ char softwareRevision[16] = {FW_VER}; char ReceivedChar = 0; int main(void) { //Initialize Board Specific Package devices BspTargetInit(); //Run loop while(1) { //Process IO data ProcessRxData(); // uartGetByte(); __delay_ms(250); //uartSndByte('c'); } } #include #include "bsp_target.h" #include "bsp_uart.h" #include "bsp_gpio.h" #include #define FCY 60000000 #define BAUDRATE (9600) #define BRGVAL ((FCY/BAUDRATE)/16)-1 static unsigned int inBytesIndex = 0; static unsigned char inBytes[MAX_UART_BUFFER_SIZE]; void BspRs485Init(void) { //Configure RX/TX pin direction // TRISCbits.TRISC8 = 0; //TX configure as output // TRISCbits.TRISC9 = 1; //RX configure as input // Setup UART functionality PPSUnLock; PPSOutput(OUT_FN_PPS_U1TX, OUT_PIN_PPS_RP56); //TX remap PPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP57); //RX remap PPSLock; U1MODEbits.UARTEN = 0; //Disable UART1, Re-enable at end of function /*UART -1 Mode settings*/ U1MODEbits.STSEL = 0; // 1-stop bit U1MODEbits.PDSEL = 0; // No Parity, 8-data bits U1MODEbits.BRGH = 0; // BRG generates 16 clocks per bit period (16x baud clock, Standard mode) U1MODEbits.URXINV = 0; // UxRX Idle state is 1 U1MODEbits.ABAUD = 0; // Autobaud Disabled U1MODEbits.LPBACK = 0; // Loop-Back Disabled U1MODEbits.WAKE = 0; // No wake up U1MODEbits.UEN = 0; // Enable UART Pins; UxTX and UxRX pins are enabled and used U1BRG = BRGVAL; // Set for 9600 /*UART -1 Status & Control Settings*/ U1STA = 0; U1STAbits.UTXBRK = 0; U1STAbits.UTXISEL0 = 0; //Interrupt when a character is transferred to the Transmit Shift Register U1STAbits.UTXISEL1 = 0; U1STAbits.URXISEL = 0; // Interrupt is set when data is transferred from the shift register to RX register /*Interrupt Controller Settings*/ IFS0bits.U1TXIF = 0; //clear the tx interupt flag IEC0bits.U1TXIE = 0; //enable transmit interupts IFS0bits.U1RXIF = 0; //clear the rx interupt flag IEC0bits.U1RXIE = 0; //enable receive interupts IPC3bits.U1TXIP = 0; //set the tx interupt level IPC2bits.U1RXIP = 0; //set the rx interupt level U1MODEbits.UARTEN = 1; //Enable Uart U1STAbits.UTXEN = 1; //Enable Transmission BspRs485EnDi***Transmit(1); } void uartSndByte(char ch) { while(U1STAbits.UTXBF); //Wait for TXREG Buffer to become available U1TXREG = ch; //Write data IFS0bits.U1TXIF = 0; //Clear the interrupt flag } void BspRs485EnDi***Transmit(uint8_t en) { if(en) CspGpioSet(RS485_TXEN_GPIO_PORT, RS485_TXEN_PIN_MSK); else CspGpioClr(RS485_TXEN_GPIO_PORT, RS485_TXEN_PIN_MSK); } void ProcessRxData(void) { unsigned char _inChar; int _inCnt; char msgLen; //while(!U1STAbits.URXDA); //Wait for a byte //return U1RXREG; if ((U1STAbits.PERR) || (U1STAbits.FERR) || (U1STAbits.OERR)) { IFS0bits.U1RXIF = 0; return; } _inChar = uartGetByte(); inBytes[inBytesIndex] = _inChar; inBytesIndex++; uartSndByte(U1RXREG); } char uartGetByte(void) { while(!U1STAbits.URXDA); //Wait for a byte return U1RXREG; } |
|
相关推荐
13个回答
|
|
这是否调用RS485缓冲区来发送或接收?
以上来自于百度翻译 以下为原文 Does this call BspRs485EnDi***Transmit(1); set the RS485 buffer to transmit, or to receive? |
|
|
|
是的,通话工作,但我必须做错误或定时问题。
以上来自于百度翻译 以下为原文 Yes, the call works, but I must be doing wrong or timing issue. |
|
|
|
你没有回答我问的问题。让我重新陈述这个问题。通过“1”到那个函数是什么?它将缓冲区设置为发送模式,还是将其设置为接收模式?
以上来自于百度翻译 以下为原文 You did not answer the question that I asked. Let me re-state the question. What does passing "1" to that function do? Does it set your buffer into transmit mode, or does it set it into receive mode? |
|
|
|
它把它设置为传输。这是示意图。
以上来自于百度翻译 以下为原文 It sets it to transmit. Here is the schematic. Attached Image(s) |
|
|
|
我认为RS485驱动程序上的发送引脚逻辑不正确。初始化时将逻辑设置为BE1,将RS485驱动程序设置为接收模式(如果将其设置为发送,则发射机将干扰接收数据)2)当您要发送时,将RS485设置为发送模式,将字节放在UART中。等待UART完全空(TRTM标志,而不是TXIF标志),并将RS485设置回接收模式。
以上来自于百度翻译 以下为原文 I think you logic for the transmit pin on the RS485 driver is not correct. The logic shoule be 1) On Initialization, set the RS485 driver to received mode (if you set it to transmit, the transmiter will interfere with the receive data) 2) When you want to transmit, set the RS485 to transmit mode, put the bytes in the UART. Wait for the UART to completely empty (TRMT flag, not the TXIF flag), and set the RS485 back to receive mode. |
|
|
|
我试过你的逻辑,但没用。可能是电缆吗?我使用这个电缆:http://www-DigiKi.com /p.Z5TCFA5IY1RHOCBXBWWWCWCWCB
以上来自于百度翻译 以下为原文 I tried your logic, but it didn't work. Could it be the cable? I'm using this cable: https://www.digikey.com/p...z5tcFA5Iy1RhoCBxbw_wcB |
|
|
|
那些是我们使用的电缆,不应该是一个问题,除非你有一个坏的。我会设置RS485接收模式,发送一些数据,看看它是否收到作为第一次测试,忘记现在的Tx,
以上来自于百度翻译 以下为原文 Those are the cables we use, should not be a problem unless you got a bad one. I would set the RS485 to receive mode, Send some data, and see if it gets received as a first test, forget Tx for now, |
|
|
|
好的,我使用P腻y。下面的图像显示了收发器的输入。图像21是从“P'”发送“C”时从电缆输入的A和B。图像22是从UC到DI和RO的输出。
以上来自于百度翻译 以下为原文 Ok so I'm using putty. The below images show the input into the transceiver. image 21 is the input into A and B from the cable when 'c' is sent from putty. image 22 is the output from DI and RO that goes to the uC. Attached Image(s) |
|
|
|
信号看起来不错,但我认为RO是倒置的。在UART设置中,您需要注意这一点。
以上来自于百度翻译 以下为原文 The signals look good, but i think RO is inverted. You will need to take care of that in the UART setup. |
|
|
|
奇怪的是,我删除了终结者(R6),现在情况好多了。它正在接收和传输,现在就得掌握逻辑。
以上来自于百度翻译 以下为原文 Well strangely enough I removed the terminator (R6) and things are better now. It's receiving and transmitting. Just gotta get the logic right now. |
|
|
|
再看看你的波形,我想你可能有D+和D反转,这将解释数据反转。
以上来自于百度翻译 以下为原文 Looking at your waveforms again, I think you may have D+ and D- reversed, which would account for the data inversion. |
|
|
|
好的,所以我拿了一些其他的波形,仍然发送Char’c。图像23:CH1A,YYXCH2B,绿色图像24:CH1RO,YOLCHCH2DI,绿色图像25:CH1A,YYLCHCH2RO,绿色接线:数据+(A)从电缆转到(Pin 6)的Max 385数据-(B)从电缆转到B(Pin 7)的Max 385,所以你是说我应该交换A和B?
以上来自于百度翻译 以下为原文 Ok so I took some other waveforms, still sending char 'c'. Image 23: Ch1 A, Yellow Ch2 B, Green Image 24: Ch1 RO, Yellow Ch2 DI, Green Image 25: Ch1 A, Yellow Ch2 RO, Green Wiring: Data+(A) from cable goes to A (pin6) of MAX3485 Data-(B) from cable goes to B (pin7) of MAX3485 So you're saying I should swap A and B? Attached Image(s) |
|
|
|
你的问题是RO是倒置的。当充电器被发送时,它应该主要是高的和低的脉冲。在某处有一个倒转。
以上来自于百度翻译 以下为原文 Your problem is RO is inverted. It should mainly be high and pulse low when a charger is sent. There is an inversion somewhere. |
|
|
|
只有小组成员才能发言,加入小组>>
5250 浏览 9 评论
2037 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2266 浏览 5 评论
788浏览 1评论
680浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
609浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 21:40 , Processed in 2.058058 second(s), Total 72, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号