*Changed* dsPIC UART Rx not working - Page 1
Forum section: electronics / projects

author: TopherTheME
author_rank: Regular Contributor
timestamp: January 20, 2011, 10:10:19 pm
content: I'm using the dsPIC30F2011 for a project which is an 18pin chip. One thing to note about the chip is that it doesn't have any RTS or CTS pins for the UART.Long story short, I've got this chip in my project with the UARX and UATX pins connected to another micro, along with two other pins, and I need to communicate between the two. Sooooo, my question is: How do you do UART communication without handshaking (or faking it) with PIC micro's? I know its possible, but the datasheet isn't very clear on how to do it. Something about keeping the Rx line high until data is sent. Anyone have a clue?

author: Mechatrommer
author_rank: Super Contributor
timestamp: January 20, 2011, 11:03:22 pm
content: i did it, with only Rx and Tx only, but not on the mentioned mcu. both line should be kept high (which is default to mcu with the feature), once get low, the receiving mcu will detect it as the beginning of comm, and start its phase locking sequence, iirc the term is. for uart, there will be always a start bit (low), for the locking do its stuff properly. and to note, both mcu must be set as the same bps setting manually by the programmer. you should see how the uart implementation/registers for your pic in the datasheet.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 20, 2011, 11:04:14 pm
content: It's entirely dependent on your application, and what you're talking to. Your device may be fast enough that it can always take the data at full speed, so no need to handshake. You may have a protocol that has acknowledges to regulate the flow of data.Serial handshaking is rarely used in embedded applications as the protocol will usually be designed to avoid the need for the extra pins- apart from general-purpose comms devices like modems & similar I don't think I've ever seen it used.

author: RayJones
author_rank: Frequent Contributor
timestamp: January 20, 2011, 11:17:43 pm
content: If you need handshaking, you could always use software handshake. ie become responsive to XON/XOFF characters embedded in the received data stream.You could also send an XOFF if you need time to handle a batch of received data....Yes it requires more work, but as already stated, it all depends upon the actual usage.If only low speed (say < 2400) you probably won't need handshaking.

author: TopherTheME
author_rank: Regular Contributor
timestamp: January 20, 2011, 11:35:22 pm
content: Thanks for the replys. I now realize that I just experienced a retard moment.I don't really "need" handshaking for my application. The UART is operating at a low enough speed that it should be just fine without the RTS/CTS lines. I just assumed that I needed it given the way the registers are setup for the UART. Just about all the other higher pin count 16-bit PICs give you the option of handshaking in the SFR setup for the UART, but this series of dsPICs does not, so I assumed it had it by default as I thought the higher pin micros in this series had CTS/RTS pins. I don't know why, I just did. But now that I look at the entire series of dsPICs I am using, I now realize that none of them have CTS or RTS pins, so obviously there would be no option for this in the configuration register.Well, that was a waste of a couple hours. I'm off to bed.

author: TopherTheME
author_rank: Regular Contributor
timestamp: January 21, 2011, 04:12:52 am
content: OK, I still can not get this dam thing to work. I don't understand why the dsPICs are so much more difficult than all the others. I got a PIC32 on the board to work just fine in minutes, but this dsPIC just simply wont.All I'm trying to do is get the Rx interrupt to work but its just not happening. Even when I run the thing in loop-back mode and spitting on stuff on the Tx pin, nothing happens. I'm stumped. Can anyone see what I'm doing wrong?Code:/***UART Example for dsPIC30F2011*/#include <p30f2011.h>#include <uart.h>//setup the UARTvoid initUART(void){U1BRG = 51;//baud rate of 9600, 8MHz XT, No PLLU1MODE = 0x8400;// Enable, 8data, no parity, 1 stop, (8-N-1), enable alternate UART pinsU1STA = 0x8400;// Enable Tx and Tx interruptwhile(U1STAbits.UTXBF==1); //empty the Tx bufferU1STAbits.OERR = 0;//clear any errors so data can be receivedIFS0bits.U1RXIF=0; /* clear UART1 receiver interrupt flag */IFS0bits.U1TXIF=0; /* clear UART1 transmitter interrupt flag */IEC0bits.U1RXIE=1; /* enable UART1 receiver ISR *///enable Rx intterupt, disable Tx interrupt//ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 & UART_TX_INT_DIS & UART_TX_INT_PR2);}//main loopint main(void){TRISD = 0;//set the direction of Port D (output)initUART();//initialize the UARTPORTD = 0x00;//set all pins are Port D lowwhile(1);//wait for something to happen}//Rx ISRvoid _ISR_PSV_U1RXInterrupt(void){putcUART1(U1RXREG);//echo back the valuePORTD = 0x01;//turn on a LEDIFS0bits.U1RXIF = 0; //clear UART1 RX interrupt flag}

author: Frangible
author_rank: Regular Contributor
timestamp: January 21, 2011, 04:41:15 am
content: It doesn't appear that you have enabled the interrupt in IEC0 (Bit 9).Add this to your init:IFS0bits.U1RXIF=0; /* clear UART1 receiver interrupt flag */IFS0bits.U1TXIF=0; /* clear UART1 transmitter interrupt flag */IEC0bits.U1RXIE=1; /* enable UART1 receiver ISR */

author: TopherTheME
author_rank: Regular Contributor
timestamp: January 21, 2011, 05:36:14 am
content: Quote from: Frangible on January 21, 2011, 04:41:15 amSorry, I pasted the wrong code. But anyway, yeah I do have that and even pasted what you posted and I still get nothing.

author: EEwannabe
author_rank: Contributor
timestamp: January 21, 2011, 09:22:18 am
content: I'm an extreme amatuer when it comes to C/C++ and probably have compiled it wrong, but other then initially clearing the transmit buffer where are you actually sending or receiveing anything in the main loop? The disassembly listing has it stuck on a branch instruction with no test condition for your While(1).-Patrick

author: RayJones
author_rank: Frequent Contributor
timestamp: January 21, 2011, 09:25:47 am
content: The Rx ISR echoes back the Rx'd character...

author: EEwannabe
author_rank: Contributor
timestamp: January 21, 2011, 09:38:55 am
content: heh, I did miss the whole ISR code when copying and pasting. : ) Probably shouldn't try and help at 3:30AM here.-Patrick