Serial Peripheral Interface (SPI) Initialized in Two Different Modes using the AVR64DD32 Microcontroller
The repository contains two MPLAB® X projects:
- Sending Data as a Host – Configuring the device in the SPI Host mode to control a Client.
- Host Client Communication – This folder contains two projects: one used to program the device as a Host and one used to program another device as a Client.
More details and code examples on the AVR64DD32 can be found at the following links:
- MPLAB® X IDE v6.00 or newer
- MPLAB® XC8 v2.36 or newer
- AVR-Dx Series Device Pack v2.1.152 or newer
To program the Curiosity Nano board with this MPLAB® X project, follow the steps provided in the How to program the Curiosity Nano Board chapter.
This example shows how to configure the device in SPI Host mode, and send data to the Client (one byte with the ASCII H
code).
The following configurations must be made for this project:
-
System clock is configured at 4 MHz
-
SPI
- SPI clock configured at 500 kHz
- SPI in Host mode
- Data mode is 0
- MSB transmitted first
- Dedicated SPI pins:
- PA4 (MOSI)
- PA5 (MISO)
- PA6 (SCK)
-
GPIO
- PA7 (SS) pin configured as output
Pin | Configuration |
---|---|
PA4 (MOSI) | Digital output |
PA5 (MISO) | Digital input |
PA6 (SCK) | Digital output |
PA7 (SS) | Digital output |
The MOSI (PA4), SCK (PA6), and SS (PA7) signals captured by a logic analyzer are shown in the image below, whereas the MISO is not shown.
When the Host asserts the SS line (low), the Host device generates the SCK signal and sends the ASCII H
code through the MOSI line.
This example shows how to configure the device in SPI Host mode, and send data to a Client.
Back to top
This example shows how to setup and initialize the SPI Host mode and SPI Client mode devices.
The device used as a Host sends the ASCII H
code through the MOSI line. The Client receives a value, if it is correct, it sends the value C
back to the Host.
If the value is not H
, the Host receives the value 0x00
from the Client.
The diagram below shows how to connect the Host board with the Client board:
The following configurations must be made for this project:
-
System clock is configured at 4 MHz
-
SPI0
- SPI clock configured at 500 kHz
- SPI in Host mode
- Data mode is 0
- MSB transmitted first
- Dedicated SPI pins:
- PA4 (MOSI)
- PA5 (MISO)
- PA6 (SCK)
-
GPIO
- PA7 (SS) pin configured as output
Pin | Configuration – Host |
---|---|
PA4 (MOSI) | Digital output |
PA5 (MISO) | Digital input |
PA6 (SCK) | Digital output |
PA7 (SS) | Digital output |
The following configurations must be made for this project:
-
System clock is configured at 4 MHz
-
SPI0
- SPI in Client mode
- Data mode 0
- MSB transmitted first
- Dedicated SPI pins:
- PA4 (MOSI)
- PA5 (MISO)
- PA6 (SCK)
- PA7 (SS)
-
GPIO
- Internal pull-up resistor enabled for PA7 (SS)
Pin | Configuration – Client |
---|---|
PA4 (MOSI) | Digital input |
PA5 (MISO) | Digital output |
PA6 (SCK) | Digital input |
PA7 (SS) | Digital input |
To test the functionality, a SPI Host device is used to exchange data with a Client.
The Host transmits the ASCII H
code as a response to character C
from the Client.
The Client can also send character C
as a response to character H
from the Host.
If the characters H
and C
are not received by the communication parties, a NULL character is transmitted.
One AVR64DD32 Curiosity Nano board is used for the SPI Host, while the other is used for the SPI Client.
For visibility, some delays have been inserted between transactions.
This example illustrated shows how to initialize two devices in order to verify the communication between those devices.
Back to top
This chapter shows how to use the MPLAB® X IDE to program an AVR® device with an Example_Project.X. This can be applied for any other projects.
-
Connect the board to the PC.
-
Open the Example_Project.X project in MPLAB® X IDE.
-
Set the Example_Project.X project as main project.
Right click the project in the Projects tab and click Set as Main Project. -
Clean and build the Example_Project.X project.
Right click the Example_Project.X project and select Clean and Build. -
Select AVRxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings.
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select AVRxxxxx Curiosity Nano (click the SN), click Apply and then OK. -
Program the project to the board.
Right click the project and then Make and Program Device.