nrf52810 spi is not working.

Hello I have an nrf52810 custom board and in this board SPI is not work. When I try to use e-paper with SPI, SPI MOSI and SCK pins are not working.

I also tried nrf52840 board and in this board everything works fine.

Overlay for nrf52810: 

Overlay for nrf52840:

Complete Code :

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/spi.h>
#include "../e_paper_lib/DEV_Config.h"
#include "../e_paper_lib/EPD_2in13_V3.h"
#include "../e_paper_lib/GUI_Paint.h"
#include "../e_paper_lib/ImageData.h"
#include <string.h>
#include <stdlib.h>

#define COLORED     0
#define UNCOLORED   1



#define MY_GPIO0 DT_NODELABEL(gpio1)
#define SPI0_NODE DT_NODELABEL(spi1)

const struct device *gpio0_dev = DEVICE_DT_GET(MY_GPIO0);
const struct device *spi0_dev = DEVICE_DT_GET(SPI0_NODE);
/*
SPI MOSI P012
SPI SCK P014
CS P09

*/
const struct spi_config spi_cfg = {

    .frequency = 4000000U, // 125000U : for slow mode

    .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER};

int main(void)
{
    wait_for_gpio0_ready();
    int ret = gpio_pin_configure(gpio0_dev, EPD_CS_PIN, GPIO_OUTPUT);
    if (ret < 0)
    {
        printk("Error .. \n");
    }

    ret = gpio_pin_configure(gpio0_dev, EPD_DC_PIN, GPIO_OUTPUT);
    if (ret < 0)
    {
        printk("Error .. \n");
    }

    ret = gpio_pin_configure(gpio0_dev, EPD_RST_PIN, GPIO_OUTPUT);
    if (ret < 0)
    {
        printk("Error .. \n");
    }

    ret = gpio_pin_configure(gpio0_dev, EPD_BUSY_PIN, GPIO_INPUT);
    if (ret < 0)
    {
        printk("Error .. \n");
    }
 Debug("EPD_2in13_V3_test Demo\r\n");
    if(DEV_Module_Init()!=0){
        return -1;
    }

    Debug("e-Paper Init and Clear...\r\n");
    EPD_2in13_V3_Init();
    EPD_2in13_V3_Clear();

    //Create a new image cache
    UBYTE *BlackImage;
    UWORD Imagesize = ((EPD_2in13_V3_WIDTH % 8 == 0)? (EPD_2in13_V3_WIDTH / 8 ): (EPD_2in13_V3_WIDTH / 8 + 1)) * EPD_2in13_V3_HEIGHT;
    if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
        Debug("Failed to apply for black memory...\r\n");
        return -1;
    }
    Debug("Paint_NewImage\r\n");
    Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);
    Paint_Clear(WHITE);
 
    Debug("show image for array\r\n");
    Paint_SelectImage(BlackImage);
    Paint_Clear(WHITE);
    Paint_DrawBitMap(gImage_2in13);

    EPD_2in13_V3_Display(BlackImage);
    DEV_Delay_ms(2000);
    Paint_NewImage(BlackImage, EPD_2in13_V3_WIDTH, EPD_2in13_V3_HEIGHT, 90, WHITE);    
    Debug("Drawing\r\n");
    //1.Select Image
    Paint_SelectImage(BlackImage);
    Paint_Clear(WHITE);
   
    // 2.Drawing on the image
    Paint_DrawPoint(5, 10, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
    Paint_DrawPoint(5, 25, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
    Paint_DrawPoint(5, 40, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
    Paint_DrawPoint(5, 55, BLACK, DOT_PIXEL_4X4, DOT_STYLE_DFT);

    Paint_DrawLine(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
    Paint_DrawLine(70, 10, 20, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
    Paint_DrawRectangle(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
    Paint_DrawRectangle(85, 10, 135, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);

    Paint_DrawLine(45, 15, 45, 55, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
    Paint_DrawLine(25, 35, 70, 35, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
    Paint_DrawCircle(45, 35, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
    Paint_DrawCircle(110, 35, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);

    Paint_DrawString_EN(140, 15, "test", &Font16, BLACK, WHITE);
    Paint_DrawNum(140, 40, 1998, &Font16, BLACK, WHITE);


    EPD_2in13_V3_Display_Base(BlackImage);
    DEV_Delay_ms(3000);



    Debug("Goto Sleep...\r\n");
    EPD_2in13_V3_Sleep();
    free(BlackImage);
    BlackImage = NULL;
    DEV_Delay_ms(2000);//important, at least 2s
    // close 5V
    Debug("close 5V, Module enters 0 power consumption ...\r\n");
    DEV_Module_Exit();

}


When I flash to the nrf52810 chip, I change spi1 and gpio1 to spi0 and gpio0. I also check the gpio pins for nrf52810 and pins work fine.

Thanks for your helps.
Parents
  • Hi,

     

    Have you scoped the SPI pins to see if there's any activity at all? 

    SPI MOSI P012
    SPI SCK P014
    CS P09

    If you are using the nrf52dk_nrf52810 board, P0.14 is "button1", so it is important that you do not enable the "DK buttons and leds" library (check that CONFIG_DK_LIBRARY is not set).

     

    Kind regards,

    Håkon

  • I already check that pins using ossiloscope but there is not any signal.

    Config file:

    # BEGIN Configurations from basic/minimal

    CONFIG_NCS_SAMPLES_DEFAULTS=y

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Test"

    # Enable the LBS service
    CONFIG_BT_LBS=n
    CONFIG_BT_LBS_POLL_BUTTON=n
    CONFIG_DK_LIBRARY=n
    CONFIG_NEWLIB_LIBC=y
    # Drivers and peripherals
    CONFIG_I2C=n
    CONFIG_WATCHDOG=n
    CONFIG_GPIO=y
    CONFIG_SPI=y
    CONFIG_SERIAL=n

    # Power management
    CONFIG_PM=n

    # Interrupts
    CONFIG_DYNAMIC_INTERRUPTS=n
    CONFIG_IRQ_OFFLOAD=n

    # Memory protection
    CONFIG_THREAD_STACK_INFO=n
    CONFIG_THREAD_CUSTOM_DATA=n
    CONFIG_FPU=n

    # Boot
    CONFIG_BOOT_BANNER=n
    CONFIG_BOOT_DELAY=0

    # Console
    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    CONFIG_STDOUT_CONSOLE=n
    CONFIG_PRINTK=n
    CONFIG_EARLY_CONSOLE=n

    # Build
    CONFIG_SIZE_OPTIMIZATIONS=y

    # ARM
    CONFIG_ARM_MPU=n
    # END Configurations from basic/minimal

    # In order to correctly tune the stack sizes for the threads the following
    # Configurations can enabled to print the current use:
    # CONFIG_THREAD_NAME=y
    # CONFIG_THREAD_ANALYZER=y
    # CONFIG_THREAD_ANALYZER_AUTO=y
    # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
    # CONFIG_THREAD_ANALYZER_USE_PRINTK=y
    # CONFIG_CONSOLE=y
    # CONFIG_UART_CONSOLE=y
    # CONFIG_SERIAL=y
    # CONFIG_PRINTK=y

    # Example output of thread analyzer
    # SDC RX              : unused 816 usage 208 / 1024 (20 %)
    # BT RX               : unused 1784 usage 416 / 2200 (18 %)
    # BT TX               : unused 992 usage 544 / 1536 (35 %)
    # thread_analyzer     : unused 136 usage 376 / 512 (73 %)
    # sysworkq            : unused 1824 usage 224 / 2048 (10 %)
    # MPSL signal         : unused 520 usage 504 / 1024 (49 %)
    # idle 00             : unused 192 usage 64 / 256 (25 %)
    # main                : unused 136 usage 888 / 1024 (86 %)
    # Configurations set based on thread analyzer output.
    CONFIG_BT_RX_STACK_SIZE=1024
    CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
    CONFIG_BT_HCI_TX_STACK_SIZE=640
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
    CONFIG_MPSL_WORK_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=1024
    CONFIG_IDLE_STACK_SIZE=128
    CONFIG_ISR_STACK_SIZE=1024


    CONFIG_DEV_CONFIG=y
    CONFIG_EPAPER_2IN13=n
    CONFIG_EPAPER_2IN13_V3=y
    CONFIG_GUI_PAINT=y
    CONFIG_IMAGE_DATA=y
    CONFIG_FONTS=y
    CONFIG_ESL_BLE=y


    # Disable features not needed
    CONFIG_TIMESLICING=n
    CONFIG_MINIMAL_LIBC_MALLOC=n
    CONFIG_LOG=n
    CONFIG_ASSERT=n

    # Disable Bluetooth features not needed
    CONFIG_BT_DEBUG_NONE=y
    CONFIG_BT_ASSERT=n
    CONFIG_BT_DATA_LEN_UPDATE=n
    CONFIG_BT_PHY_UPDATE=n
    CONFIG_BT_GATT_CACHING=n
    CONFIG_BT_GATT_SERVICE_CHANGED=n
    CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
    CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
    CONFIG_BT_HCI_VS_EXT=n

    # Disable Bluetooth controller features not needed
    CONFIG_BT_CTLR_PRIVACY=n
    CONFIG_BT_CTLR_PHY_2M=n

    # Reduce Bluetooth buffers
    CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
    CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43
    CONFIG_BT_BUF_EVT_RX_COUNT=2

    CONFIG_BT_CONN_TX_MAX=2
    CONFIG_BT_L2CAP_TX_BUF_COUNT=2
    CONFIG_BT_CTLR_RX_BUFFERS=1
    CONFIG_BT_BUF_ACL_TX_COUNT=3
    CONFIG_BT_BUF_ACL_TX_SIZE=27
     
    Also here is the spi write function:

    void DEV_SPI_WriteByte(UBYTE value)
    {
        struct spi_buf bufs[] = {
            {
                .buf = &value,
                .len = 1
            },
        };

        struct spi_buf_set tx = {
            .buffers = bufs,
            .count = 1
        };

        spi_write(spi0_dev, &spi_cfg, &tx);

       
    }
  • I also configured nrfx_spim example for e-papers. The example works fine with nrf52840 but it did not work for nrf52810.

  • Could you please share your build/zephyr/zephyr.dts file for the non-working scenario?

     

    Kind regards,

    Håkon

  • Hi,

     

    Both I2C0 and SPI0 is enabled simultaneously in your compiled zephyr.dts. These are shared peripherals and cannot be enabled simultaneously.

    Try disabling I2C0 (or changing it to I2C1/I2C2) and see if it starts to work.

     

    Kind regards,

    Håkon

  • Thank you very much indeed! It solved my problem
Reply Children
Related