Abour uart TX question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Abour uart TX question

716 Views
haoyuancai
Contributor II

Dear all:

      I am confuse recently. When I use uart to send my command and I use PC to receive data(PS: I have used converter to change TTL  voltage to RS232 voltage).Because this part code will be used many times in program(in a loop).the data is correct most of time. but there are still some error data inside . But I have checked  the data in the send buffer of my code is correct, But the data that I  received is error. who can help me ?

code:

    fwrite((pointer)Trans_buffer,sizeof(unsigned char),lenth,upload_dev);

   

   

    fflush(upload_dev);

   

    ioctl( upload_dev, IO_IOCTL_SERIAL_WAIT_FOR_TC, NULL );

I use these three line code to send data

Trans_buffer : the data in this buffer is always correct.

example of my data :

77 10 80 00 00 77 12 80 00 00 77 14 80 00 00 77 16 80 00 00 77 18 80 00 00 77 1A 80 00 00

77 1C 80 00 00 77 1E 80 00 00 77 20 80 00 00 77 22 80 00 00 77 24 80 00 00 77 26 80 00 00

77 28 80 00 00 77 2A 80 00 00 77 2C 80 00 00 77 2E 80 00 00 77 30 80 00 00 77 80 32 00 00

77 34 80 00 00 77 36 80 00 00 77 38 80 00 00 77 3A 80 00 00 77 3C 80 00 00 77 3E 80 00 00

77 40 80 00 00 77 42 80 00 00 77 44 80 00 00 77 46 80 00 00

The red data is error, we can find the second data and the third data exchanged their place.

I dont know how to solve this problem.

the data send to PC through a voltage converter and Serial port to USB port line    ( PIN:TX RX GND )

0 Kudos
5 Replies

490 Views
haoyuancai
Contributor II

Hey David . I use MQX version is 4.0.

deivce is developed by myself. I did not use the development board that made by freescale .

I use the Keil IDE

project is a little big .I can not post all project maybe . I can post some .c file to u .

In addition, I found I change my baudrate to 19200 or 38400 . The problem never happened again.

:smileyhappy:

0 Kudos

490 Views
DavidS
NXP Employee
NXP Employee

Hi Haoyuan,

If the baud change fixes it....keep it :-).

With your custom board and software, have you changed the clock configuraiton?  Depending on the core/bus clock configuration maybe the 19200 baud had too much error and 38400 does not.

Regards,

David

0 Kudos

490 Views
haoyuancai
Contributor II

David:

        But I still want to solve this problem . I find my macro definition of bus_clock_  is 48000000. But my external oscillator is 50Mhz. I am not sure if it will affect the stability of baud rate.

:smileyhappy:

0 Kudos

490 Views
DavidS
NXP Employee
NXP Employee

Hi Haoyuan,

Please post your code/project so I may look at it.

Regards,

David

0 Kudos

490 Views
DavidS
NXP Employee
NXP Employee

Hi Haoyuan,

Could some other task be overwriting the buffer from time to time?

What MQX version?  What device and/or tower and/or freedom hardware are you using?

What development tools?

Can you post your project?

Regards,

David

0 Kudos