• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How do I interface a pic24 with a rs232 barcode reader?

Thread starter #1
I have a pic24FJ1024GB10 explorer board, and a brand new LS2208 barcode scanner. The barcode scanner outputs 5V. Im trying to read the serial rs233 signal using only the ground, tx, rx, pins from the barcode reader with no success. I have analyzed the signal coming from the barcode reader using Saleae logic software and the output is read correctly using a 9600 baud rate, 8-bit transfer mode, 1 stop bit, no parity bit, least significant bit sent first, inverted. So the signal seems to be sending correctly and I'm initializing the board with the same parameters. The Saleae output is attached.

The barcode scanner reference manual is too large to attach but the pdf can be found here:
https://www.zebra.com/content/dam/z...ners/ls2208-product-reference-guide-en-us.pdf

C:
void InitU1(void){
U1MODEbits.BRGH = 0;
U1BRG =12;
U1MODE =0x8070;
RPINR18 = 0x000E;
U1STA = 0x5400;

TRISBbits.TRISB1 = 1; // enable RTS , output

RPINR18bits.U1CTSR = 6; //set CTS pin RP6
//RPINR18bits.U1RXR = 14; //set RX pin RP8
RPOR0bits.RP1R = 3; //set TX pin RP1
RPOR1bits.RP3R = 4; //set RTS pin RP3

}
char getU1 (void)
{
//RTS = 0; // telling the other side !RTS
//while (!U1STAbits.URXDA ); // wait
//RTS =1; // telling the other side RTS

return U1RXREG ; // from receiving buffer
}
int main(void) {
LCD_Initialize();
InitU1();

int i=0;

char readRX;
char rx[15];

ms_delay(120);

readRX = getU1();
ms_delay(2);
printf("Value of readRX %c\n", readRX);
ms_delay(100);

while(i<14){
for (i=0; i<15; i++){
rx[I] = getU1();[/I]

[I]ms_delay(1);
}
}[/I]

[I]printf("\f");
printf("RX input: %s\n", rx);[/I]

[I]ms_delay(100);[/I]

[I]}
[/I]
 

Attachments

Last edited by a moderator:

Pommie

Well-Known Member
Most Helpful Member
#3
You don't appear to be checking if a byte is available!

Mike.
Edit looking at the manual, it's standard RS232. If so you'll need a MAX232 chip. Try plugging it into a P.C. via an RS232 to USB cable and run a terminal to see if you can get it working.
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
#4
As already mentioned, it's standard serial at 9600 baud, and very simple to use. You don't seem to have any working serial routines in your code?, why not use MCC which will generate known working routines for you?.

A good idea would be to connect the PIC serial port (via an FDTI USB converter) to your PC, run comms software (I like to use Termite) on the PC and check everything works before even starting with the barcode reader. You could also connect the reader through the FDTI as well, and use it directly on the PC to confirm what you get.
 

Latest threads

EE World Online Articles

Loading

 
Top