Hi,
I have a custom nRF9160 board. ADXL362 & MX25R64 share the same SPI bus. I'm trying to validate it individually and looks like there is no communication between both nRF9160 & the 2 peripherals.
I'm using nRF9160 DK to program my custom board. I'm using v2.7.0 toolchain & v2.6.1 SDK. I am using custom board files, it was created as mentioned in the Dev Academy lessons.
For ADXL362, I'm using the sample accel_polling. Here's everything related to spi3 in the devicetree.
/ {
aliases {
accel0 = &adxl362;
};
};
&spi3 {
status = "okay";
cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>; /* ADXL362 CS */
adxl362: adxl362@0 {
compatible = "adi,adxl362";
status = "okay";
reg = <0>;
spi-max-frequency = <1000000>; // 8MHz is typically max for ADXL362
int1-gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
};
};
&spi3 {
compatible = "nordic,nrf-spim";
status = "okay";
// cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */
pinctrl-0 = <&spi3_default>;
pinctrl-1 = <&spi3_sleep>;
pinctrl-names = "default", "sleep";
};
&pinctrl {
spi3_default: spi3_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
<NRF_PSEL(SPIM_MISO, 0, 5)>,
<NRF_PSEL(SPIM_MOSI, 0, 4)>;
nordic,drive-mode = <NRF_DRIVE_H0H1>;
};
};
spi3_sleep: spi3_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
<NRF_PSEL(SPIM_MISO, 0, 5)>,
<NRF_PSEL(SPIM_MOSI, 0, 4)>;
low-power-enable;
};
};
};This is the output:
[00:00:00.880,340] <err> ADXL362: wrong part_id: 0 *** Booting nRF Connect SDK 3758bcbfa5cd *** ADXL362 Test[00:00:00.880,432] <err> main: Accelerometer device not found
NOR Flash related details:
Overlay:
&spi3 {
status = "okay";
cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
mx25r64: mx25r6435f@0 {
compatible = "jedec,spi-nor";
status = "okay";
reg = <0>;
spi-max-frequency = <8000000>;
jedec-id = [c2 28 17];
size = <67108864>; // 64MB
has-dpd;
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
};
};
&mx25r64 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
external_storage: partition@0 {
label = "external-storage";
reg = <0x00000000 0x4000000>; // Full 64MB
};
};
};
main.c
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/storage/flash_map.h>
int main(void)
{
const struct device *flash_dev = DEVICE_DT_GET(DT_NODELABEL(mx25r64));
if (!device_is_ready(flash_dev))
{
printk("External flash device not ready\n");
return -1;
}
uint8_t write_buf[] = "Hello, External Flash!";
uint8_t read_buf[sizeof(write_buf)];
off_t offset = 0;
// Erase
if (flash_erase(flash_dev, offset, sizeof(write_buf)) != 0)
{
printk("Flash erase failed\n");
return -1;
}
// Write
if (flash_write(flash_dev, offset, write_buf, sizeof(write_buf)) != 0)
{
printk("Flash write failed\n");
return -1;
}
// Read
if (flash_read(flash_dev, offset, read_buf, sizeof(read_buf)) != 0)
{
printk("Flash read failed\n");
return -1;
}
// Verify
if (memcmp(write_buf, read_buf, sizeof(write_buf)) == 0)
{
printk("Data written and read successfully!\n");
}
else
{
printk("Data verification failed\n");
}
return 0;
}