Page 2 of 2
Re: NXC: Non-responsive RS485 Receive
Posted: 07 Jun 2012, 03:47
by haydenstudios
Thanks for trying to help, but all that changes is the order of operations in displaying the rectangle, which doesn't have any effect on how the program behaves. The rectangle shows up on the slave screen in both my version and yours, and we even know that it's receiving an RS485 message from the master NXT every thirty milliseconds due to the rapid beeping I'm hearing. The problem is it's constantly somehow receiving the value zero. So the problem is in the RS485 operation.
Re: NXC: Non-responsive RS485 Receive
Posted: 07 Jun 2012, 04:39
by mattallen37
I know that. The way you programmed the display is bad. You programmed it to display the rectangle for 30ms, and then clear the screen until you get the next message.
Anyhow, I think I know what the RS485 problems is. RS485Read expects an array to copy the RS485 Rx buffer into, not an int. Try this:
Code: Select all
inline void WaitForMessageToBeSent()
{
while(RS485SendingData())
Wait(1);
}
byte Rx_Buffer[];
task main()
{
UseRS485();
// make sure the RS485 system is turned on
RS485Enable();
// initialize the UART to default values
// RS485Initialize();
// configure the UART (this is equivalent to RS485Initialize)
RS485Uart(HS_BAUD_DEFAULT, HS_MODE_DEFAULT);
Wait(1);
int BallX, BallY, Position1, Position2 = 0, SensorOld, SensorNew;
TextOut(0, LCD_LINE4, "Sanding by...");
//Stand by until an RS485 message is received
while(true)
{
until(RS485DataAvailable());
RS485Read(Rx_Buffer);
Position1 = Rx_Buffer[0];
//Wait until it receives a message, and write that number as the position
PlayTone(500, 25);
//Play a sond to indicate that it is indeed receiving a message
ClearScreen();
RectOut(Position1, 0, 24, 4);
//Display the tray at the received postition
}
}
Re: NXC: Non-responsive RS485 Receive
Posted: 07 Jun 2012, 14:13
by haydenstudios
mattallen37 wrote:Anyhow, I think I know what the RS485 problems is. RS485Read expects an array to copy the RS485 Rx buffer into, not an int. Try this:
Code: Select all
inline void WaitForMessageToBeSent()
{
while(RS485SendingData())
Wait(1);
}
byte Rx_Buffer[];
task main()
{
UseRS485();
// make sure the RS485 system is turned on
RS485Enable();
// initialize the UART to default values
// RS485Initialize();
// configure the UART (this is equivalent to RS485Initialize)
RS485Uart(HS_BAUD_DEFAULT, HS_MODE_DEFAULT);
Wait(1);
int BallX, BallY, Position1, Position2 = 0, SensorOld, SensorNew;
TextOut(0, LCD_LINE4, "Sanding by...");
//Stand by until an RS485 message is received
while(true)
{
until(RS485DataAvailable());
RS485Read(Rx_Buffer);
Position1 = Rx_Buffer[0];
//Wait until it receives a message, and write that number as the position
PlayTone(500, 25);
//Play a sond to indicate that it is indeed receiving a message
ClearScreen();
RectOut(Position1, 0, 24, 4);
//Display the tray at the received postition
}
}
Guess what? It's working! Thanks Matt!
Re: NXC: Non-responsive RS485 Receive
Posted: 07 Jun 2012, 14:36
by mattallen37
Great! You're welcome.