2
\$\begingroup\$

I have a LED Display which has a RS232 connector so that we can connect it to our system. Display board accept whatever data we type in hyper terminal and display it. For e.g if I type Hello in terminal, it will display Hello.

Now I have an AVR Devlopment Board. I have programmed the MCU to transmit Hello at delay of 2sec. I have connected the RS232 cable of display board to the AVR development board. It should display the Hello message but its not displaying anything. I have tried including <cr><lf> also because when we hit enter at the hyper terminal, only then it accepts the data. But still not able to display. Any suggestions where I am missing the point?

CODE

void serial_Init()
{
UCSRB = (1<<TXEN) | (1<<RXEN);
UCSRC = (1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
UBRRL = 51;

}
void serial_Tx(char *str)
{
for (unsigned int i=0;str[i]!=0;i++)
{
    UDR=str[i];
    while(!(UCSRA&(1<<UDRE)));

}
}

int main()
{
serial_Init();
while(1)
{   

    {

        serial_Tx("HELLO");
        serial_Tx("0x0D");
        serial_Tx("0x0A");
    }

    }

}
\$\endgroup\$
  • \$\begingroup\$ Does the AVR board have an RS232 driver such as MAX232? Have you matched baud rate and other settings such as parity and number of stop bits? See if hyper terminal can receive data from your AVR board. Also make sure you have initialized the AVR serial comms properly- port pins etc. \$\endgroup\$ – Spehro Pefhany Oct 13 '15 at 11:02
  • \$\begingroup\$ Have you tried first with loop-back option? TX of AVR->RX of AVR? \$\endgroup\$ – TicTacToe Oct 13 '15 at 11:02
  • \$\begingroup\$ @Zola Spehro Pefhany AVR development board is working fine. I have tested it with many other modules and I always get data at terminal. It has MAX232 \$\endgroup\$ – Aircraft Oct 13 '15 at 11:05
  • \$\begingroup\$ What protocol that display use to communicate with controling unit? \$\endgroup\$ – TicTacToe Oct 13 '15 at 11:09
  • \$\begingroup\$ It doesn't have any protocol . When i send the data from the PC serially( via hyper terminal) it works but not working with controller. \$\endgroup\$ – Aircraft Oct 13 '15 at 11:10
2
\$\begingroup\$

The first thing to check is the baud rate.

If you think the baud rate is right, look at the serial line with a scope. The PC gives you the known working case, which you compare against the non-working case.

This is just basic debugging.

\$\endgroup\$
  • \$\begingroup\$ Baudrate is correct but I didn't get you look at the serial line with a scope ? \$\endgroup\$ – Aircraft Oct 13 '15 at 11:07
  • \$\begingroup\$ @CZAbhinav Look at the signal with an oscilloscope and check that it is outputting and that it is correct. \$\endgroup\$ – efox29 Oct 13 '15 at 11:27
  • 1
    \$\begingroup\$ @CZAbhinav And if you didn't look at signal with an oscilloscope, how can you tell that the baudrate is correct? Setting up the baudrate in the microcontroller UART hardware is not always a trivial task. \$\endgroup\$ – Lundin Oct 13 '15 at 11:44
  • \$\begingroup\$ @Lundin I can say that baud rate is correct because I was receiving the data at the terminal. \$\endgroup\$ – Aircraft Oct 13 '15 at 13:04
  • 1
    \$\begingroup\$ @Lundin I tested my code by connecting RS232 cable to my pc, and I was receiving data but when I connected the RS232 cable of display board to my dev. board, it didn't show up anything.! \$\endgroup\$ – Aircraft Oct 13 '15 at 16:59
0
\$\begingroup\$

If the code you've posted is correct then here are the mistakes:

1) The function void serial_Tx(char *str) accepts char * and you call it 3 times with:

    serial_Tx("HELLO");
    serial_Tx("0x0D");
    serial_Tx("0x0A");

in this case mcu sends this bytes over serial line with the seq numbers (1st line):

                            1                   2
seq:      1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
first:    H E L L O 0 x 0 D 0 x 0 A
second:   H E L L O 0d0a

as you see the (single message) size 13 bytes and there is no cr lf in it. If the display commits message upon receiving cr+lf then it is normal to not to show anything.

In the second line i put the message with cr+lf thus the message size is 7 bytes.

So the code should be: serial_Tx("HELLO\r\n");

2) The transmitting code is in an endless while loop. So mcu never stops sending data! If with this code, you connect your mcu to your PC and open HYPERTERM you will observe that your HYPERTERM and uart will lock up because of flood.

So the code should be:

int main() {
    serial_Init();

    serial_Tx("HELLO\r\n");

    while(1) {  }    
}
\$\endgroup\$
  • \$\begingroup\$ I have tried sending serial_Tx("HELLO\r\n");, nothing seems to work. But your second point looks interesting because I am including serial_Tx("HELLO\r\n"); in while(1) which is continuously sending it and may be display board is accepting only one time. I'll definitely try it before while(1). Thanks.! \$\endgroup\$ – Aircraft Oct 17 '15 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.