Skip to content

Commit 1a0cbdb

Browse files
committed
samples: Add spi master sample
- Simple sample that sends bytes to SPI slave - Tested on beagleconnect freedom Signed-off-by: Ayush Singh <[email protected]>
1 parent 069b597 commit 1a0cbdb

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

samples/spi_controller/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE})
6+
set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay)
7+
8+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
9+
project(spi_controller)
10+
11+
target_sources(app PRIVATE src/app.cpp)
12+
13+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)

samples/spi_controller/README.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. _spi_controller:
2+
3+
SPI Controller
4+
###############
5+
6+
Overview
7+
********
8+
9+
A simple sample that sends incrementing byte to SPI peripheral.

samples/spi_controller/prj.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_CPLUSPLUS=y
2+
CONFIG_ARDUINO_API=y
3+
CONFIG_SPI=y
4+
CONFIG_LOG=y
5+
CONFIG_LOG_OUTPUT=y
6+
CONFIG_LOG_MODE_IMMEDIATE=y

samples/spi_controller/src/app.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2024 Ayush Singh <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "SPI.h"
8+
#include <Arduino.h>
9+
10+
#define CHIPSELECT 3
11+
12+
static uint8_t data = 0;
13+
14+
void setup() {
15+
SPI.begin();
16+
pinMode(CHIPSELECT, OUTPUT);
17+
digitalWrite(CHIPSELECT, HIGH);
18+
}
19+
20+
void loop() {
21+
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
22+
digitalWrite(CHIPSELECT, LOW);
23+
SPI.transfer(data++);
24+
digitalWrite(CHIPSELECT, HIGH);
25+
SPI.endTransaction();
26+
delay(1000);
27+
}

0 commit comments

Comments
 (0)