NXC: Non-responsive RS485 Receive

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
haydenstudios
Posts: 252
Joined: 22 Oct 2010, 20:05
Location: The United States of America
Contact:

Re: NXC: Non-responsive RS485 Receive

Post 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.
-Hayden
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Non-responsive RS485 Receive

Post 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
  }
}
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
haydenstudios
Posts: 252
Joined: 22 Oct 2010, 20:05
Location: The United States of America
Contact:

Re: NXC: Non-responsive RS485 Receive

Post 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!
-Hayden
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: Non-responsive RS485 Receive

Post by mattallen37 »

:D Great! You're welcome.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests