Hi all,
I have 2 MCUs communicating in RS485 style. I am able to transmit a character "A" from MCU1 (master) to MCU2 (slave)by a push-button. (Initial GPIO pin of RS485 for MCU1 is high & GPIO pin of RS485 MCU2 is low).
MCU2 received the character "A" correctly & light up LED2. Thus, MCU2 (slave) acknowledge this by sending back 2 character "OK" to MCU1 & light up LED1 of MCU1. (The GPIO of both MCUs are toggled in order to perform the above operations).
However, if I add the command highlighted below to switch the GPIO pin of RS485 of MCU2 (slave) back to low. The above operation of transmitting "OK" fails. If i remove the highlighted command, MCU1 receive it correctly (monitor by HyperTerminal)
Why is that so? I need to set it low to continue to listen. How should I correctly set my P5OUT BIT7 back to low to listen?
The interrupt code of both Tx & Rx (for MCU2) is as follows:
#pragma vector=USART0TX_VECTOR
_interrupt void usart0_tx (void)
{
TXBUF0 = string[i++]; //To transmit "OK" to MCU1
if(k == sizeof string -1)
IE1 &= ~UTXIE0; //disable Tx interrupt of MCU2
P5OUT &= ~BIT7; //Set RS485 pin of MCU2 back to low
}
#pragma vector=USART0RX_VECTOR
_interrupt void usart0_rx (void)
{
if(RXBUF0 == 'A') //check for transmission from MCU1 for incoming "A"
{
i=0;
P5OUT |=BIT7; set the RS485 pin to transmit of MCU2 so that it prepares to acknowledge
P4OUT |=BIT1; on led 2 of MCU2
IE1 |=UTXIE0; //Enable tx interrupt
TXBUF0 = string[i++];
}