-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09a2635
commit 9a49a9d
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
|
||
# Pull in SDK (must be before project) | ||
include(../../lib/pico-sdk/pico_sdk_init.cmake) | ||
|
||
project(fram_read C CXX ASM) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Initialize the SDK | ||
pico_sdk_init() | ||
|
||
add_compile_options( | ||
-Wall | ||
-Wno-format | ||
-Wno-unused-function | ||
) | ||
|
||
add_executable(${PROJECT_NAME} | ||
${PROJECT_NAME}.cpp | ||
) | ||
|
||
add_subdirectory(${PROJECT_SOURCE_DIR}/../../lib/MB85RS-Pico ${CMAKE_BINARY_DIR}/MB85RS-Pico) | ||
|
||
# Include project and library headers | ||
target_include_directories(${PROJECT_NAME} | ||
PRIVATE | ||
${PROJECT_SOURCE_DIR}/../../lib/MB85RS-Pico | ||
) | ||
|
||
# Pull in common dependencies | ||
target_link_libraries(${PROJECT_NAME} | ||
pico_stdlib | ||
MB85RS-Pico | ||
) | ||
|
||
pico_enable_stdio_usb(${PROJECT_NAME} 1) | ||
pico_enable_stdio_uart(${PROJECT_NAME} 0) | ||
|
||
# Create uf2 file | ||
pico_add_uf2_output(${PROJECT_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @file fram_read.cpp | ||
* @author csg83 | ||
* | ||
* @brief Reads out the contents of FRAM | ||
*/ | ||
|
||
#include "pico/stdlib.h" | ||
#include "mb85rs.hpp" | ||
#include "../../src/pins.hpp" | ||
#include "tusb.h" | ||
#include <cstdio> | ||
|
||
#define BYTES_TO_READ 20 | ||
|
||
MB85RS fram(SPI_PORT, FRAM_CS); | ||
|
||
int main() { | ||
stdio_init_all(); | ||
|
||
gpio_init(FRAM_CS); | ||
gpio_set_dir(FRAM_CS, GPIO_OUT); | ||
|
||
spi_init(SPI_PORT, 125 * 1000000 / 6); | ||
gpio_set_function(SPI_MISO, GPIO_FUNC_SPI); | ||
gpio_set_function(SPI_MOSI, GPIO_FUNC_SPI); | ||
gpio_set_function(SPI_SCK, GPIO_FUNC_SPI); | ||
gpio_put(FRAM_CS, 1); | ||
|
||
while (!tud_cdc_connected()) { | ||
sleep_ms(500); | ||
} | ||
printf("Connected\n"); | ||
|
||
if (!fram.begin()) { | ||
printf("Error: FRAM begin unsuccessful\n"); | ||
} | ||
|
||
uint8_t data[BYTES_TO_READ] = {0}; | ||
uint8_t temp = 42; | ||
|
||
fram.write_bytes(0, &temp, 1); | ||
|
||
if (fram.read_bytes(0, data, BYTES_TO_READ)) { | ||
for (int i = 0; i < BYTES_TO_READ; i++) { | ||
printf("(%d): %d\n", i, data[i]); | ||
} | ||
} else { | ||
printf("Error: FRAM read unsuccessful\n"); | ||
} | ||
|
||
return 0; | ||
} |