TReX Jr - Serial packets not received

Hi there,

I am using an ATmega644PA microcontroller to send commands to a TReX Jr motor controller via the TTL serial ports. I’ve connected the TReX Jr GND pin to my microcontroller’s GND, I’ve connected the TReX Jr SO pin to my microcontroller’s Rx pin, I’ve connected the TReX Jr SI pin to my microcontroller’s Tx pin. When I power on the TReX Jr, the blue led goes solid and the red led flashes 5 times and then also goes solid (on). But no matter what I do, I cannot get the green led to flash, indicating that a serial packet has been received by the TReX Jr. The final application for this motor controller will be for a single motor, connected to either M1 or M2.

I have reset the serial communications parameters (pololu.com/docs/0J5/5.g) and have set the baud-rate of the ATmega644PA to 19.2kbps (default of the TReX Jr). But nadda. I also have a FT232 hooked up to the serial ports on the microcontroller and then to my computer via USB. I can see that serial packets are, in fact, being sent by the ATmega644PA, but not being received by the TRex Jr.

Any thoughts?

- Michael

Hello.

Can you post the simplest program you think should work but does not?

Also, can you try using your USB-to-TTL-serial adapter to send commands to the TReX Jr? One simple way would be with our Serial Transmitter Utility, but you might also try the TReX Configurator Utility or our sample C# program for communicating with the TReX.

- Ben

I’m running the ATmega644PA microcontroller using a simple MATLAB GUI. Press a button in the GUI and the microcontroller sends something to the TReX Jr. The code responsible for sending commands to the TReX Jr is:

  k = receive();

  if(k == '1')
  {
    sprintf(buffer, "%x", 0xf0);
    write_uart2(buffer);
  }

Where “k=1” corresponds to a particular button being pressed in the MATLAB GUI and write_uart2 is the #1 serial port on the microcontroller (with 19,200 bps baud rate). It doesn’t matter if I send ‘0xf0’ or ‘0x80’ or anything else - I still get no green led flash showing that the data has been received by the TRex Jr. If you don’t see some obvious fault in the code, I can look into using the USB directly to the motor controlled, but would like to avoid it (I need the ATmega644PA for other tasks and instruments, all of which will be tied in with the TReX Jr).

It might help to know the write_uart2 function. Here are two functions: the first is to initiate the UART, the second is to send data.

void uart_init()
{
	//Set Baud rate to 19,200
	UBRR1H = UART_UBBR_VALUE2 >> 8;
	UBRR1L = UART_UBBR_VALUE2;
	UCSR1A |= (1<<U2X0);
	//Frame format: 8 data bits, no parity, 1 stop bit
	UCSR1C |= (1<<UCSZ11)|(1<<UCSZ10);
	//Enable Transmit and Receive
	UCSR1B |= (1<< RXEN1)|(1<<TXEN1);
}
void write_uart2(unsigned char c[])
{
	do 
	{
		while((UCSR1A&(1<<UDRE1)) == 0); // Wait for Transmit Buffer to Empty
		UDR1 = *c; // Transmit the character
		c++; // Increment the pointer to point to the next character
	}while(*c != '\0');
}

Hello.

The sprintf function generates an ASCII string. The TReX does not use ASCII. You should make a function that can write arbitrary bytes to the UART, including 0, and then use that to send the right byte.

Something like this could work:

void write_uart2_byte(unsigned char c)
{
  while((UCSR1A&(1<<UDRE1)) == 0); // Wait for Transmit Buffer to Empty
  UDR1 = c;
}

–David

David, thanks for that! It’s late and I won’t be able to test it until the morning, but the TReX Jr is showing that data is being received. Cross your fingers, but it looks like it’ll all work out from here.

Thanks again, and I’ll let you guys know if anything else goes not as expected.

- Michael