This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART transmitting wrong char

Hello, I am trying to set UART connection for the first time. I have a LPC2138 protoboard and I want to use its UART to transmit char A to bluetooth module RN41 via its UART. I managed to send something through but the char recieved on bt module is not the one send from LPC2138. For example if i try to transmit A i get AC on the other end.

Can anyone help me with this problem?

this is my code:

#include <stdio.h>

#define PINSEL0 (*((volatile unsigned long *) 0xE002C000))
#define PINSEL1 (*((volatile unsigned long *) 0xE002C004))
#define PINSEL2 (*((volatile unsigned long *) 0xE002C014))

//UART0
#define U0RBR (*((volatile unsigned char *) 0xE000C000))
#define U0THR (*((volatile unsigned char *) 0xE000C000))
#define U0IER (*((volatile unsigned char *) 0xE000C004))
#define U0IIR (*((volatile unsigned char *) 0xE000C008))
#define U0FCR (*((volatile unsigned char *) 0xE000C008))
#define U0LCR (*((volatile unsigned char *) 0xE000C00C))
#define U0LSR (*((volatile unsigned char *) 0xE000C014))
#define U0SCR (*((volatile unsigned char *) 0xE000C01C))
#define U0DLL (*((volatile unsigned char *) 0xE000C000))
#define U0DLM (*((volatile unsigned char *) 0xE000C004))
#define U0TER (*((volatile unsigned char *) 0xE000C030))

int main(void)
{

PINSEL0 = 0x5;

U0LCR = 0x83;
U0DLL = 78;
U0DLM = 0x00;
U0LCR = 0x03;

U1LCR = 0x83;
U1DLL = 78;
U1DLM = 0x00;
U1LCR = 0x03;

while(1)
{

while (!(U0LSR & 0x20)); //transmit condition
U0THR = 0x2D;

}
}

Parents
  • 1) You really do hate software comments, don't you?

    2) Is there anything wrong with using the header files available for your processor, instead of creating your own definitions of all registers?

    3) We don't know what clocking you have. We don't want what baudrate you want. So how will we be able to figure out if you set the correct baudrate for the UART?

    4) You do like magic constants don't you:

    U0THR = 0x2D;
    


    If you want to send a 'A', why do you then supply the numeric value for a '-'? Wouldn't it be 100 times better to write:

    U0THR = 'A';
    


    in which case it really would be an 'A' and not a '-' that you write to the transmit holding register...

    5) How do you know what character the bluetooth device receives? Have you looked at the signal lines with an oscilloscope, or how can the RN41 module tell you what it sees? It is always a good idea to verify baudrates with an oscilloscope.

Reply
  • 1) You really do hate software comments, don't you?

    2) Is there anything wrong with using the header files available for your processor, instead of creating your own definitions of all registers?

    3) We don't know what clocking you have. We don't want what baudrate you want. So how will we be able to figure out if you set the correct baudrate for the UART?

    4) You do like magic constants don't you:

    U0THR = 0x2D;
    


    If you want to send a 'A', why do you then supply the numeric value for a '-'? Wouldn't it be 100 times better to write:

    U0THR = 'A';
    


    in which case it really would be an 'A' and not a '-' that you write to the transmit holding register...

    5) How do you know what character the bluetooth device receives? Have you looked at the signal lines with an oscilloscope, or how can the RN41 module tell you what it sees? It is always a good idea to verify baudrates with an oscilloscope.

Children
No data