Skip to content

Arduino UNO (ATmega328P) - SPI communication from scratch

License

Notifications You must be signed in to change notification settings

abdullahbagyapan/spi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPI (Serial Peripheral Interface) Communication Between Two Arduino's

This project walks you through the process building an AVR application to exercise the SPI and UART on the ATmega328p microcontroller.

Prerequisites

We need to install library, compiler, binary to hex converter, and AVR MCU programmer

These applications can be install by following line:

sudo apt install avr-libc avrdude binutils-avr gcc-avr

The Code

Master

The code below initializes the SPI module as master and prepare that for use. The while loop transmit message using SPI.

int main(void) {

    SPI_MasterInit();


    while (1) {

        SPI_PutString("Hello World !\r\n");

    }

    return 0;
}

Slave

The code below initializes the UART and SPI module and prepare them for use. The while loop receive message from SPI and transmit it by UART.

int main(void) {

    SPI_SlaveInit();
    UART_Init();

    while (1) {

        uint8_t ui8Data = SPI_GetChar();
        
        UART_PutChar(ui8Data);
        
    }

    return 0;
}

Compiling The Code

To compile the source code we need to create a Makefile to automate the process. Makefiles allow us to place all build/clean/flash commands into one easy to use file. Each microcontroller has a unique set of parameters prior to compiling and deploying. These commands are listed a the top of the Makefile and are easily changed.

Now that your Makefile is complete issue the make from the command start the build process.

Master

make -f Makefile-master

Slave

make -f Makefile-slave

Flashing The Code

Now that we compiled the code we can deploy to our microcontroller.

Master

make -f Makefile-master flash

Slave

make -f Makefile-slave flash

About

Arduino UNO (ATmega328P) - SPI communication from scratch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages