Micro controller Networking - UART to SPI bridge

There are many parts used in embedded systems.In most cases,we have to transfer data between these components.In this tutorial we're going to look how to receive data from UART module in a PIC micro and transfer those data to another component using SPI module.Using this method we can transfer single input to multiple receivers because we can use more than one component in SPI.

In here,PIC16F887 micro controller is used as the UART receiver and it'll send the received data via it's SPI module.MikroC PRO is used for the writing the firmware.You can download the FREE(with some limitations) version from,


MikroC PRO Download Page


This is the code used.First we initialize UART module to work at 9600bps.
Then we initialize SPI module.Then the code is to check whether there is data coming to UART module and if so,just relay them to SPI module.The last line will send received data again to another UART receiver via UART Tx pin.

You can find more info on these modules form MikroC knowledge base.

SPI Library

UART Library

void main() {
char receive;
UART1_Init(9600);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_END,
_SPI_CLK_IDLE_HIGH, _SPI_LOW_2_HIGH);
while(1){
if (UART1_Data_Ready() == 1) {
receive = UART1_Read();
SPI1_Write(receive);
UART1_Write(receive);
}
}


Circuit with PIC16F887 Slave with this PIC16F887 Master:(Click on image to get high resolution schematic)



In the next post,we'll build a simple motor controller slave with this :D
Share on Google Plus
    Blogger Comment

1 comments:

  1. i am using this tow software for my development. wish you all the best

    ReplyDelete