Author Topic: *Changed* dsPIC UART Rx not working  (Read 10516 times)

0 Members and 1 Guest are viewing this topic.

Offline TopherTheMETopic starter

  • Regular Contributor
  • *
  • Posts: 196
*Changed* dsPIC UART Rx not working
« on: January 20, 2011, 10:10:19 pm »
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?
« Last Edit: January 21, 2011, 05:38:07 am by TopherTheME »
Don't blame me. I'm the mechanical engineer.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11632
  • Country: my
  • reassessing directives...
Re: Using UART communication without "handshaking"
« Reply #1 on: January 20, 2011, 11:03:22 pm »
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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13747
  • Country: gb
    • Mike's Electric Stuff
Re: Using UART communication without "handshaking"
« Reply #2 on: January 20, 2011, 11:04:14 pm »
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.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: Using UART communication without "handshaking"
« Reply #3 on: January 20, 2011, 11:17:43 pm »
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.
 

Offline TopherTheMETopic starter

  • Regular Contributor
  • *
  • Posts: 196
Re: Using UART communication without "handshaking"
« Reply #4 on: January 20, 2011, 11:35:22 pm »
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.  :(

Don't blame me. I'm the mechanical engineer.
 

Offline TopherTheMETopic starter

  • Regular Contributor
  • *
  • Posts: 196
Re: Using UART communication without "handshaking"
« Reply #5 on: January 21, 2011, 04:12:52 am »
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: [Select]
/*
**UART Example for dsPIC30F2011
*/

#include <p30f2011.h>
#include <uart.h>


//setup the UART
void initUART(void)
{
    U1BRG     = 51; //baud rate of 9600, 8MHz XT, No PLL
  U1MODE = 0x8400; // Enable, 8data, no parity, 1 stop, (8-N-1), enable alternate UART pins
  U1STA = 0x8400;  // Enable Tx and Tx interrupt
  while(U1STAbits.UTXBF==1); //empty the Tx buffer
U1STAbits.OERR = 0; //clear any errors so data can be received

IFS0bits.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 loop
int main(void)
{
TRISD = 0;  //set the direction of Port D (output)
initUART(); //initialize the UART
PORTD = 0x00;     //set all pins are Port D low
while(1); //wait for something to happen
}

//Rx ISR
void _ISR_PSV_U1RXInterrupt(void)
{
putcUART1(U1RXREG); //echo back the value
PORTD = 0x01; //turn on a LED
    IFS0bits.U1RXIF = 0;    //clear UART1 RX interrupt flag   
}

« Last Edit: January 21, 2011, 05:35:03 am by TopherTheME »
Don't blame me. I'm the mechanical engineer.
 

Offline Frangible

  • Regular Contributor
  • *
  • Posts: 109
  • Country: us
  • Contraptioneer
Re: Using UART communication without "handshaking"
« Reply #6 on: January 21, 2011, 04:41:15 am »
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 */

 

Offline TopherTheMETopic starter

  • Regular Contributor
  • *
  • Posts: 196
Re: Using UART communication without "handshaking"
« Reply #7 on: January 21, 2011, 05:36:14 am »
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 */



Sorry, I pasted the wrong code. But anyway, yeah I do have that and even pasted what you posted and I still get nothing.
Don't blame me. I'm the mechanical engineer.
 

Offline EEwannabe

  • Contributor
  • Posts: 38
  • Country: us
Re: *Changed* dsPIC UART Rx not working
« Reply #8 on: January 21, 2011, 09:22:18 am »
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
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: *Changed* dsPIC UART Rx not working
« Reply #9 on: January 21, 2011, 09:25:47 am »
The Rx ISR echoes back the Rx'd character...
 

Offline EEwannabe

  • Contributor
  • Posts: 38
  • Country: us
Re: *Changed* dsPIC UART Rx not working
« Reply #10 on: January 21, 2011, 09:38:55 am »
heh, I did miss the whole ISR code when copying and pasting. : ) Probably shouldn't try and help at 3:30AM here.

-Patrick
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf