Try first the polling mode, as suggested in my reply #3 with USART1 (Serial2), RXD1=PA12, TXD1=PA13, RST1=PA14 (see Greynomad pinaout diagram) :
void setup()
{
pinMode(23, OUTPUT); //RTS for USART1
digitalWrite(23, LOW);
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1); //SERIAL_8N1
//USART1->US_WPMR = 0x55534100; //Unlock the USART Mode register, just in case. (mine wasn't locked).
USART1->US_CR |= US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS;
USART1->US_MR |= US_MR_USART_MODE_RS485 //USART1 IN RS485 mode
| US_MR_PAR_NO // No parity
| US_MR_OVER; // 8 X oversampling
USART1->US_CR |= US_CR_TXEN | US_CR_RXEN; //Enable Transmitter and Receiver
}
void loop()
{
char mydat = 0;
while (1)
{
while (Serial2.available()) // USART1
{
mydat = Serial2.read();
if (mydat != 0)
{
Serial.println(mydat);
}
if (mydat == 's') //check if char 's' received if yes then transmit for test
{
delay(100);
digitalWrite(23, HIGH); //for transmitter RTS HIGH
Serial2.println("waiting for char");
Serial2.flush(); //Wait till transmit all char
digitalWrite(23, LOW);
delay(100);
mydat = 0;
}
}
}
}