rs485 simulation

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

rs485 simulation

1,490 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by james on Tue Mar 06 21:18:23 MST 2012
Hi guy,

I need to test my program which uses the uart1 (txd1, p0.15 and rxd1, p0.16) to send commands via rs485 @ 9600baud.

How can I check if my program is setup properly? Is there a way to do a loopback check or loop to other pins?

Thanks aplenty :)
0 项奖励
回复
6 回复数

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Wed Mar 14 10:43:06 MST 2012

Quote: james
i added a 1ms delay now before cutting off the Enable. Now everything works fine :)


No it's not.

You are checking LSR & 0x20. I prefer to write 1<<5 so I immediately know this is bit 5 which is THRE (Transmit Holding Register Empty) and this does not say anything about the status of the TX data line. Most likely you wanted to check for the TEMT (Transmitter Empty) which is bit 6.
But even that you don't want...

What you want is to use the RS485 capabilities of the UART itself and for this you should read the user manual. The UART has auto direction control, relieving you of the task to toggle the output pin. You can specify how long after the stop bit the RS485 transceiver should be disabled. You can exactly specify how many bits the transceiver should be active before becoming inactive (I would suggest to use a 1 bit delay as a start).
With the auto address detect feature you even have less to worry about.

If you select UART1 for it's RS485 capabilities, better use them well.

Regards,[INDENT]Rob
[/INDENT]
0 项奖励
回复

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by james on Wed Mar 14 01:23:44 MST 2012
Thanks rob,

How embarrassing... it was actually a simple delay problem :x.
I got the problem fixed! :)

while( (LPC_UART0->LSR & 0x20) == 0 );   
I though this code would have provided the delay to ensure all bits have been transmitted before cutting off the Enable.

On closer inspection, i noticed my data had been cut off 2bits too early. so i added a 1ms delay now before cutting off the Enable. Now everything works fine :)
0 项奖励
回复

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Mar 13 23:53:27 MST 2012

Quote: james
does my implementation work? Or what did i implemented wrongly?



You measured data coming out so apparently something is working.

You did not tell us where you see the data.
You should check:

[LIST]
[*]Data lines leaving and entering the LPC1768
[*]RS485 bus lines
[*]on your device's board both the RS485 bus and the data lines to/from it's controller.
[/LIST]
What does your hardware look like?
How do you control the DE and /RE lines of your transceiver(s)?
Did you ever try to tie /RE look just to see if you get a local echo?
Did you ever try to just connect the Rx/Tx lines without a transceiver to see if there is a problem with the receiving part of your program?


I am also wondering if you are correct in assuming (or letting us believe) that the device you are talking to will respond when you send any character twice over the line. Normally there will be some sort of protocol and you have to adhere to that protocol for the device to respond.


From a software side you are not using any of the RS485 features of the UART in your code. The UART has RS485 in that it may handle the enabling of the tranceiver (where you are using P1.24) , handling of any delays between the sending of the stop bit and disabling the transceiver and address detection of the incoming packets.
Are you sure that the whole transaction has completed (i.e. the stop bit has been sent out) before you are disabling the transceiver ?
My implementation of UART0_SendChar() would just return without waiting for the UART communication to complete (keyword: FIFO).


I think you should have a close look at your code, the code inside the functions you are calling and also read the user manual to understand what the RS485 mode of the UART can do for you.



Regards,
[INDENT]Rob

[/INDENT]
0 项奖励
回复

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by james on Tue Mar 13 21:06:50 MST 2012
Thanks for the replies,

I am sending signals of 9600baud, 1start, 1stop, 8bits, no parity. As I need the UART1 for other devices, I have to use UART0 for rs485 communication. I am using a GPIO p1.24 for the enable control. p0.2 to Tx and p0.3 to Rx of max485.

I modified the UART example and changed

<code>
UART0_Init(9600);
LPC_GPIO1->FIOSET = Enable;
UART0_Sendchar(c);
UART0_Sendchar(c);
LPC_GPIO1->FIOCLR = Enable;
            while(1)
            {
                cout = UART0_Getchar();
                printf("%d\n",cout);
            }

</code>

After sending the 2byte, I should be getting response from the device I am talking to. However the the response i got was 0.

I check with a picoscope and confirmed that there was data been sent out.

From the 1768 user manual, only UART1 was stated to have RS485 support, does my implementation work? Or what did i implemented wrongly?

Please advise.
0 项奖励
回复

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by js-nxp on Wed Mar 07 13:43:45 MST 2012
What communication protocol are you using for the RS485?
0 项奖励
回复

1,250 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Polux rsv on Wed Mar 07 00:59:08 MST 2012
Use a USB->TTL serial cable. Not a RS232 port/cable, voltage level are not compatible. And check the data using a terminal software on your PC.
Or setup Uart0 and connect it to Uart1: Tx0 on Rx1, Rx0 on Tx1.

Angelo
0 项奖励
回复