1

Cant send character 'C' and display on receiver pic. LCD prints some special characters, no 'C'... ;(

Transmiter:

char uart_rd;
int uart_rdi;

sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;


void main() {
  ANSELA  = 0;                     // Configure AN pins as digital
  ANSELB = 0;
  ANSELC = 0;

  Lcd_Init();

  UART2_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize



 while (1) {

   UART2_Write('C');
   }
 }

Receiver:

char uart_rd;
int uart_rdi;

sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;


void main() {
  ANSELA  = 0;                     // Configure AN pins as digital
  ANSELB = 0;
  ANSELC = 0;

  Lcd_Init();

  UART2_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize


 while (1) {
    if (UART2_Data_Ready()) {     // If data is received,
     uart_rdi = UART2_Read();     // read the received data,
       uart_rd = uart_rdi;
      LCD_Out(1,1, uart_rd);

   }
 }
}

Unsing two pics 18F26K22, new to serial ports... dont know how to test it as dont have equipment, is my code is good? Im not using Proteus, working on metal. THANKS.

  • Can you attach a debugger to the receiver PIC and see if it is receiving the character correctly vs. just not displaying it to the LCD correctly? Alternatively, flip a light on/off if it sees a character and/or the correct character. Also, UART modules don't need time to "stabilize", you divide the system clock and end up with a specific bit-rate. Clock instabilities are negligible by the time the processor boots and begins executing code. – Nick T May 20 '14 at 22:28
  • What do you mean by debugger as if you are talking about oscilloscope, I dont have it... – Vadimas Sizikovas May 20 '14 at 22:35
  • Im getting something from sending pic, but i cant display it on receiver pic as it display some symbols but not C letter... – Vadimas Sizikovas May 20 '14 at 22:41
  • Is your receiver powered on and running before you attempt to transmit? Also, the receiver might pick up garbage while power is rising to the transmitter. By debugger I mean something like the [ICD 3](http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=DV164035) or [PICkit 3](http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=PG164130). – Nick T May 20 '14 at 22:53
  • Add a delay (maybe 10 ms) in your write loop, so you're not writing characters back to back. Do you know how many stop bits you're sending? – Hot Licks May 20 '14 at 22:58
  • Try modifying the receiver side to send the received byte back instead of/in addition to displaying it. Then, on the sender side, compare it with what you've really sent. It will give you an immediate indication if serial channel is misconfigured (mismatched clock/baud/parity/stop bits). – oakad May 21 '14 at 03:13

1 Answers1

2

I had once this problem, and the fact was that the character was not a unsigned char. so try to cast it.

...
while (1) {
if (UART2_Data_Ready()) {     // If data is received,
  uart_rdi = UART2_Read();     // read the received data,
  uart_rd = uart_rdi;
  LCD_Out(1,1, (unsigned char) uart_rd);
...
jlucidar
  • 106
  • 1
  • 8