Skip to content

Commit

Permalink
samples: Add spi master sample
Browse files Browse the repository at this point in the history
- Simple sample that sends bytes to SPI slave
- Tested on beagleconnect freedom

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed Jun 19, 2024
1 parent 86d2583 commit 63d6bbb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions samples/spi_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE})
set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spi_controller)

target_sources(app PRIVATE src/app.cpp)

zephyr_compile_options(-Wno-unused-variable -Wno-comment)
9 changes: 9 additions & 0 deletions samples/spi_controller/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _spi_controller:

SPI Controller
###############

Overview
********

A simple sample that sends incrementing byte to SPI peripheral.
6 changes: 6 additions & 0 deletions samples/spi_controller/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONFIG_CPLUSPLUS=y
CONFIG_ARDUINO_API=y
CONFIG_SPI=y
CONFIG_LOG=y
CONFIG_LOG_OUTPUT=y
CONFIG_LOG_MODE_IMMEDIATE=y
27 changes: 27 additions & 0 deletions samples/spi_controller/src/app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 Ayush Singh <ayush@beagleboard.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "SPI.h"
#include <Arduino.h>

#define CHIPSELECT 3

static uint8_t data = 0;

void setup() {
SPI.begin();
pinMode(CHIPSELECT, OUTPUT);
digitalWrite(CHIPSELECT, HIGH);
}

void loop() {
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
digitalWrite(CHIPSELECT, LOW);
SPI.transfer(data++);
digitalWrite(CHIPSELECT, HIGH);
SPI.endTransaction();
delay(1000);
}

0 comments on commit 63d6bbb

Please sign in to comment.