Commit 477952f
oclyke
patch full duplex SPI transfers after migration to AmbiqSuite SDK 2.4.2 HAL
Copied functionality from 2.2.0 version of HAL. Will ultimately want to fix this. Tested with this sketch:
```
#include "SPI.h"
#define CS_PIN 13
SPISettings MySPISettings(14000000, MSBFIRST, SPI_MODE0);
/////////////////////////////////////////////
// Set TX and RX values for various data types
uint8_t tx_val_8 = 0xAA;
uint8_t rx_val_8 = 0x00;
uint16_t tx_val_16 = 0xABBA;
uint16_t rx_val_16 = 0x00;
const uint8_t msg_len = 8;
uint8_t tx_msg[msg_len] = {'H', 'e', 'l', 'l', 'o', '!', '!', 0};
uint8_t rx_msg[msg_len] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t single_buff[msg_len] = {'t', 'e', 's', 't', ' ', 'p', 'a', 't'};
uint8_t single_buff_copy[msg_len] = {0, 0, 0, 0, 0, 0, 0, 0};
/////////////////////////////////////////////
// Main test
void setup() {
Serial.begin(115200);
SPI.begin();
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
memcpy(single_buff_copy, single_buff, msg_len); // copy single buff for comparison after the fact
delay(100);
Serial.println("\n\nApollo3 SPI Full Duplex Test Sketch\n");
/////////////////////////////////////////////
// SPI Transaction with tests of each data type transfer (connect MOSI to MISO)
SPI.beginTransaction(MySPISettings);
digitalWrite(CS_PIN, LOW);
rx_val_8 = SPI.transfer(tx_val_8); // test 8-bit fullduplex (Arduino API)
rx_val_16 = SPI.transfer16(tx_val_16); // test 16-bit fullduplex (Arduino API)
SPI.transferOutIn(tx_msg, rx_msg, msg_len); // test buffer fullduplex (API extension - shows HW capability)
SPI.transfer(single_buff, msg_len); // test out/in in-place (Arduino API)
digitalWrite(CS_PIN, HIGH);
SPI.endTransaction();
/////////////////////////////////////////////
// Check if received values match sent values
Serial.print("SPI.transfer(uint8_t); RESULT: "); test_8bit_match();
Serial.print("SPI.transfer16(uint16_t); RESULT: "); test_16bit_match();
Serial.print("SPI.transferOutIn(void*, void*, size_t); RESULT: "); test_msg_match(tx_msg, rx_msg, msg_len);
Serial.print("SPI.transfer(void*, size_t); RESULT: "); test_msg_match(single_buff_copy, single_buff, msg_len);
Serial.println();
}
void loop() {
}
void test_8bit_match( void ){
if(rx_val_8 != tx_val_8){
Serial.printf("Error: failed fullduplex\n\tSent 0x%02X, received 0x%02X\n", tx_val_8, rx_val_8);
}else{
Serial.printf("Passed!\n");
}
}
void test_16bit_match( void ){
if(rx_val_16 != tx_val_16){
Serial.printf("Error: failed fullduplex\n\tSent 0x%04X, received 0x%04X\n", tx_val_16, rx_val_16);
}else{
Serial.printf("Passed!\n");
}
}
void test_msg_match( uint8_t* tx, uint8_t* rx, size_t len ){
bool msg_match = true;
for(uint8_t ix = 0; ix < len; ix++){
if(tx[ix] != rx[ix]){
msg_match = false;
break;
}
}
if(!msg_match){
Serial.printf("Error: failed fullduplex\n\tSent: { ");
for(uint8_t ix = 0; ix < len; ix++){
if(ix != 0){
Serial.print(", ");
}
Serial.print((char)tx[ix]);
}
Serial.print("}, recieved { ");
for(uint8_t ix = 0; ix < len; ix++){
if(ix != 0){
Serial.print(", ");
}
Serial.print((char)rx[ix]);
}
Serial.print("}\n");
}else{
Serial.printf("Passed!\n");
}
}
```1 parent 72b62bb commit 477952f
File tree
4 files changed
+454
-20
lines changed- cores/arduino/ard_sup
- iomaster
- libraries/SPI/src
4 files changed
+454
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
0 commit comments