Hi MartinL thanks
With the following code i can transmit and receive via RS485
But i need interrupt enable reception.
How i can do that? Please check my code
void setup()
{
pinMode(RTS, OUTPUT); //RTS for USART1
digitalWrite(RTS,LOW);
Serial.begin(9600);
MeterSerial.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 |= 0X8C1;//USART1 IN RS485 mode
USART1->US_CR |= US_CR_TXEN|US_CR_RXEN; //Enable Transmitter and Receiver
void loop()
{
char mydat = 0;
while(1)
{
while(MeterSerial.available())
{
mydat = MeterSerial.read();
if(mydat!=0)
{
Serial.println(mydat);
}
if(mydat == 's') //check if char 's' received if yes then transmit for test
{
delay(100);
digitalWrite(RTS,HIGH); //for transmitter RTS HIGH
MeterSerial.println("wating for char");
MeterSerial.flush(); //Wait till transmit all char
digitalWrite(RTS,LOW);
delay(100);
mydat = 0;
}
}
}
Now I am not getting that how to enable interrupt when receiving data
I have searched and study and found US_IER to enable interrupt for transmitter and receiver
But how to define interrupt function?
I am trying and if success then will upload the code
if any idea then reply