This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to modify nrf9160DK Asset_Tracker to add SPI slave functionality

I am just getting started with the nrf9160DK and need to prototype using that board as an SPI slave to receive data and send via cellular (the stock sample code compiles and runs perfectly).  After reviewing multiple articles on the development forum [problems with SPI on nRF9160 and Zephyr] I am still unable to configure an SPI device and have it show with device_get_binding().  I am using Segger on Debian Linux as a development environment.  Below are the changes I have made at this time.  Can someone point my in the right direction?  Since I am new to Zephyr, I will also need some guidance on how to asynchronously receive SPI data in the asset_tracker sample.

1. Start with the base asset_tracker sample

2. Add a file 'nrf9160_pca10090.overlay' with the following contents (changing to spi2, or removing the ss-pin definition does not help):
&spi3 {
status = "ok";
sck-pin = <26>;
mosi-pin = <27>;
miso-pin = <29>;
ss-pin = <28>;
spi-max-frequency = <4000000>;
};

3. Modify the existing prj.conf by adding the following settings:
CONFIG_LOG=Y
CONFIG_SERIAL=Y
CONFIG_STDOUT_CONSOLE=Y
CONFIG_UART_INTERRUPT_DRIVEN=Y
CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=Y
CONFIG_PRINTK=Y
CONFIG_LOG_PRINTK=Y
CONFIG_GPIO=Y
CONFIG_SPI=Y
CONFIG_SPI_NRFX=Y
CONFIG_SPI_3=Y
CONFIG_SPI_3_NRF_SPIM=Y

4. Add the following function to 'main.c' and call it after the first printk in main():
static void spi_init(void)
{
 const char* const spiName = "SPI_3";
 struct device *const spi_dev = device_get_binding(spiName);

 if (spi_dev == NULL) {
 printk("Could not get %s device\n", spiName);
 return;
 }

 return;
}


Parents Reply
  • Hi,

     

    RicFlair said:
    Do you also happen to have one similar for I2C for the Asset Tracker example?

    It's on my todo-list, but haven't gotten that far yet. No promises this week.. Should be fairly similar to how the SPI module is setup, but do note that the SPIM / TWIM share the same base, meaning that you cannot have SPIM0 and TWIM0 active at the same time. It'll have to be SPIM1 and TWIM0 for instance.

     

    Kind regards,

    Håkon

Children
Related