I was using mikroC for the coding because programming microcontrollers in C is much easier than using Assembly. The C code for RS232 communication is pretty easy.
You only need four methods to use the USART module (Universal Synchronous/Asynchronous Receiver/Transmitter). USART_init() method initializes the USART module and sets the bit rate etc. USART_Read() and USART_Write() methods can read and write one Byte of data at a time. USART_Data_Ready() is used to check whether the data has arrived.
What this simple program does is read the data send by the computer and repeat it back to the computer one character at a time. While this program alone is not much of a use in practice, the same theory can be used to do something useful.
What caught my attention is that since a single microcontroller chip can both send and receive data; two microcontrollers can communicate with each other with the same protocol, without the need of a computer or any other interface between them. And since this is serial communication, only one data line is needed. So, we can connect two microcontrollers with just two wires and send any command or data between them.
I know that theoretically this should work, so I'm putting together the circuit to test it practically. I'll post the progress of it as it goes along.
void main(){
USART_init(9600); // initialize USART module
// (8 bit, 9600 baud rate, no parity bit...
while (1){
if (USART_Data_Ready()){ // if data is received
i = USART_Read(); // read the received data
USART_Write(i); // send back via USART
}
}
}
You only need four methods to use the USART module (Universal Synchronous/Asynchronous Receiver/Transmitter). USART_init() method initializes the USART module and sets the bit rate etc. USART_Read() and USART_Write() methods can read and write one Byte of data at a time. USART_Data_Ready() is used to check whether the data has arrived.
What this simple program does is read the data send by the computer and repeat it back to the computer one character at a time. While this program alone is not much of a use in practice, the same theory can be used to do something useful.
What caught my attention is that since a single microcontroller chip can both send and receive data; two microcontrollers can communicate with each other with the same protocol, without the need of a computer or any other interface between them. And since this is serial communication, only one data line is needed. So, we can connect two microcontrollers with just two wires and send any command or data between them.
I know that theoretically this should work, so I'm putting together the circuit to test it practically. I'll post the progress of it as it goes along.
Comments
Post a Comment