Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART with PIC24F and Parallax 28040

Status
Not open for further replies.

milesguidon

Member level 2
Joined
Dec 4, 2010
Messages
52
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,288
Location
Los Angeles, CA
Activity points
1,753
I am using the UART TX and RX ports on my PIC24F04KA200 to send and receive data to/from the bi-directional signal pin on a Parallax 28040 temperature sensor module. Is anybody familiar enough with programming UART on the PIC in C to glance at these code snippets and give me some advice on where I'm going wrong so far? Thanks:

const char Txdata[] = "0!TEMR$5A$07";
char Rxdata[2]="00";

int main(void)
{
init_U1MODE();
init_U1STA();
//Set Baud rate to 9600
U1BRG=25;

//Write Txdata[] to U1TX1REG
int k;
for(k=13; k>0; k--)
{
_UTXEN=0; //make sure TX is disabled
U1TXREG=Txdata[k]; //load the word, one char at a time
_UTXEN=1; //enable TX, char gets sent
}
_UTXEN=0; //disable TX--we're done sending this word

//Read U1RX1REG only if receive buffer isn't overflown
char lowByte, highByte;
if(_OERR==0) //if we dont have an overflow in the RX buffer
{
blink_LED1();
lowByte = U1RXREG;
pause_1();
highByte = U1RXREG;
}
//Fill Rxdata[] with the low and high bytes
Rxdata[0]=lowByte;
Rxdata[1]=highByte;
.......

void init_U1MODE()
{
//U1MODE configuration: auto Baud enable, 8-bit data, no parity bit, 1 stop bit, normal baud rate
U1MODE=0x8210;
}

void init_U1STA()
{
//Initializes the U1 status -- transmit off, etc.
_UTXISEL1=0;
_UTXISEL0=1;
_UTXINV=1;
_UTXBRK=1;
_UTXEN=0;
_URXISEL1=1;
_URXISEL0=0;
_ADDEN=0;
}

I took the main chunks that I'm concerned with from my code, which all compiles fine. The character array in the beginning is what I am sending to the Parallax module -- I built this string based on what I think is the correct command syntax to send to the 28040 to get it to reply with output. I found the commands in the Parallax 28040 datasheet, which is here:

**broken link removed**

Command !TEMr is described on Page 4.

I'd love any guidance at all! I'm doing this from scratch, and it's my 6th day working with any sort of microprocessor -or- UART communication protocol...and to top it all off, C isn't my strong suit.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top