[RTL8722CSM] [RTL8722DM] SPI - Slave Receive

Materials

  • AmebaD[AMB21 / AMB22] x 1

  • Arduino UNO x 1

Steps

SPI is a fast and robust communication protocol that are commonly found on many microcontrollers and is often used to retrieve sensor data or output image signal to a display. Ameba support SPI in both master and slave mode. Here we are going to see an example demonstrating how ameba receive data in slave mode on MicroPython.

Before connection, make sure to upload the following code to your Arduino UNO.

 1///////////////////////
 2// SPI Master Write //
 3///////////////////////
 4#include <SPI.h>
 5void setup (void) {
 6             Serial.begin(115200); //set baud rate to 115200 for usart
 7             digitalWrite(SS, HIGH); // disable Slave Select
 8             SPI.begin ();
 9}
10void loop (void) {
11             char c;
12             digitalWrite(SS, LOW); // enable Slave Select
13             // send test string
14             for (const char * p = "Hello, world!\r" ; c = *p; p++) {
15             SPI.transfer(c);
16             Serial.print(c);
17                     }
18                Serial.println();
19             digitalWrite(SS, HIGH); // disable Slave Select
20             delay(2000);
21}

Connection is shown as follows, here we are using unit 0 as SPI slave, and Arduino UNO as SPI master,

image1

Then copy and paste the following code into REPL under paste mode to see their effects.

1from machine import SPI
2s1= SPI(0 , mode = SPI.SLAVE)
3for i in range(14):
4chr(s1.read())