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

Help with using TWI with the NRF52832 (SES studio)

Hi everyone,

So I've this arduino code that utilizes the I2C library and made some convertions to it to work with the nrf52832 in the segger embedded studio and when debugging the code never passes the "err_code = nrf_drv_twi_tx();"

function and is always stuck in the hard error tab or the

"while (m_xfer_done == false);"

line.

now I've used the example TWI_sensor as the base project for the convertion no idea what to do and I got frustrated with using this nordic platform

Could anyone tell me maybe what am I doing wrong?

here is the arduino code:

    #include<Wire.h>

#define OLED_ADDR 0x3C


#define BLACK 0
#define WHITE 1
#define INVERSE 2

#define SSD1306_I2C_ADDRESS   0x3C  // 011110+SA0+RW - 0x3C or 0x3D
// Address for 128x32 is 0x3C
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)

/*=========================================================================
    SSD1306 Displays
    -----------------------------------------------------------------------
    The driver is used in multiple displays (128x64, 128x32, etc.).
    Select the appropriate display below to create an appropriately
    sized framebuffer, etc.

    SSD1306_128_64  128x64 pixel display

    SSD1306_128_32  128x32 pixel display

    SSD1306_96_16

    -----------------------------------------------------------------------*/
   #define SSD1306_128_64
//#define SSD1306_128_32
//   #define SSD1306_96_16
/*=========================================================================*/

#if defined SSD1306_128_64 && defined SSD1306_128_32
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
#error "At least one SSD1306 display must be specified in SSD1306.h"
#endif

#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH                  128
#define SSD1306_LCDHEIGHT                 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH                  128
#define SSD1306_LCDHEIGHT                 32
#endif
#if defined SSD1306_96_16
#define SSD1306_LCDWIDTH                  96
#define SSD1306_LCDHEIGHT                 16
#endif


#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF

#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA

#define SSD1306_SETVCOMDETECT 0xDB

#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9

#define SSD1306_SETMULTIPLEX 0xA8

#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10

#define SSD1306_SETSTARTLINE 0x40

#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDR 0x21
#define SSD1306_PAGEADDR   0x22

#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8

#define SSD1306_SEGREMAP 0xA0

#define SSD1306_CHARGEPUMP 0x8D

#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2

// Scrolling #defines
#define SSD1306_ACTIVATE_SCROLL 0x2F
#define SSD1306_DEACTIVATE_SCROLL 0x2E
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A


static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {

  // My buffer
  0x00, 0x00, 0x00, 0x3E, 0x7E, 0x7F, 0xE7, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3,
  0xE3, 0xFF, 0x7F, 0x7E, 0x1C, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x70, 0x38, 0x38, 0x18, 0x1C, 0x1C,
  0x0C, 0x0C, 0x0C, 0x0C, 0xEC, 0x2C, 0x2C, 0x2C, 0x8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0x00, 0x0F, 0x08, 0x00, 0x00, 0x07, 0x0A, 0x0A, 0x0B, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x8E, 0xCE, 0xCE, 0xCE, 0xCE,
  0xCE, 0xFF, 0xFF, 0xFF, 0xFF, 0xCE, 0xCE, 0x8C, 0x0C, 0x1C, 0x1C, 0x38, 0xF8, 0xF0, 0xE0, 0x00,
  0x03, 0x07, 0x0F, 0x0E, 0x1C, 0x1C, 0x98, 0x99, 0xB9, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0xB9,
  0xB9, 0xB9, 0x38, 0x38, 0x70, 0x70, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xFC, 0x04, 0x04, 0x8C, 0xF8, 0x00, 0x00, 0x10, 0x00, 0x00, 0xFC, 0x0C,
  0x30, 0xC0, 0xC0, 0x30, 0x0C, 0xFC, 0x00, 0xF4, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x00, 0xFC,
  0x10, 0x10, 0xF0, 0x00, 0x00, 0xD0, 0x50, 0x50, 0xF0, 0x00, 0x00, 0xE0, 0x50, 0x50, 0x60, 0x00,
  0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x20, 0x20, 0x20, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0x70, 0x70, 0x38, 0x39, 0xB9, 0xB9, 0xB9,
  0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0xB9, 0x98, 0x98, 0x1C, 0x1C, 0x0E, 0x0F, 0x07, 0x03, 0x00,
  0x00, 0x00, 0x00, 0x3E, 0x3F, 0x7F, 0x73, 0x63, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3,
  0x63, 0x7F, 0x7F, 0x3F, 0x1C, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0E, 0x0E, 0x0C, 0x1C, 0x1C,
  0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x18,
  0x18, 0x19, 0x19, 0x18, 0x18, 0x19, 0x18, 0x19, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18, 0x19,
  0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18,
  0x18, 0x19, 0x18, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x1C, 0x1C,
  0x1C, 0x0C, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0x7F, 0x63, 0xE3,
  0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0x63, 0x7F, 0x7F, 0x3F, 0x1E, 0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
  0x1F, 0x7F, 0xFF, 0xFC, 0xF0, 0xE0, 0xC0, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x83,
  0x83, 0x83, 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x83, 0x83, 0x83, 0x83,
  0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0xC3, 0xC1, 0xC0, 0xE0, 0xF0, 0xFC, 0xFF, 0x7F, 0x1F, 0x00,
  0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x87, 0x87, 0x8F, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x8F,
  0x8F, 0x8F, 0x0F, 0x1F, 0x3F, 0x7E, 0xFC, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x78, 0xC0, 0xC0, 0x38, 0x0C, 0xE0, 0x50, 0x50,
  0x60, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x30, 0x50, 0xD0, 0x00, 0x00, 0x00, 0xF4, 0x00, 0x00, 0xF0,
  0x10, 0x10, 0xF0, 0x00, 0x00, 0xF0, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x04, 0x04,
  0xFC, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x24, 0x24, 0x24, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xFC, 0x3E, 0x3F, 0x1F, 0x0F, 0x8F, 0x8F, 0x8F,
  0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x8F, 0x87, 0x87, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0x1F, 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0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03,
  0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x3F, 0x7F, 0x7C, 0xFC,
  0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0x7C, 0x7F, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00
#endif
#endif

};

int8_t _i2caddr, vccstate = SSD1306_SWITCHCAPVCC, sid, sclk, dc, rst, cs;

void setup() {

    Wire.begin();

    // Init sequence
    ssd1306_command(SSD1306_DISPLAYOFF);                    // 0xAE
    ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
    ssd1306_command(0x80);                                  // the suggested ratio 0x80

    ssd1306_command(SSD1306_SETMULTIPLEX);                  // 0xA8
    ssd1306_command(SSD1306_LCDHEIGHT - 1);

    ssd1306_command(SSD1306_SETDISPLAYOFFSET);              // 0xD3
    ssd1306_command(0x0);                                   // no offset
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0);            // line #0
    ssd1306_command(SSD1306_CHARGEPUMP);

    // 0x8D

    
      if (vccstate == SSD1306_EXTERNALVCC)
      { ssd1306_command(0x10); }
      else
      {
    ssd1306_command(0x14); }
    ssd1306_command(SSD1306_MEMORYMODE);                    // 0x20
    ssd1306_command(0x00);                                  // 0x0 act like ks0108
    ssd1306_command(SSD1306_SEGREMAP | 0x1);
    ssd1306_command(SSD1306_COMSCANDEC);

#if defined SSD1306_128_32
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x02);
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    ssd1306_command(0x8F);

#elif defined SSD1306_128_64
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x12);
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    if (vccstate == SSD1306_EXTERNALVCC)
    {
      ssd1306_command(0x9F);
    }
    else
    {
      ssd1306_command(0xCF);
    }

#elif defined SSD1306_96_16
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x2);   //ada x12
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    if (vccstate == SSD1306_EXTERNALVCC)
    {
      ssd1306_command(0x10);
    }
    else
    {
      ssd1306_command(0xAF);
    }

#endif

    ssd1306_command(SSD1306_SETPRECHARGE);                  // 0xd9
      if (vccstate == SSD1306_EXTERNALVCC)
        { ssd1306_command(0x22); }
      else
        { ssd1306_command(0xF1); }


    ssd1306_command(SSD1306_SETVCOMDETECT);                 // 0xDB
    ssd1306_command(0x40);
    ssd1306_command(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
    ssd1306_command(SSD1306_NORMALDISPLAY);                 // 0xA6

    ssd1306_command(SSD1306_DEACTIVATE_SCROLL);

    ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel
    //ssd1306_command(SSD1306_INVERTDISPLAY);

    display();
    delay(2000);
    
}



  void loop() {

    ssd1306_command(SSD1306_INVERTDISPLAY);
    delay(1000);
    ssd1306_command(SSD1306_NORMALDISPLAY);
    delay(1000);

  }

  void ssd1306_command(uint8_t Command) {

    uint8_t control = 0x00;
    Wire.beginTransmission(OLED_ADDR);
    Wire.write(control);
    Wire.write(Command);
    Wire.endTransmission();

  }

  void display() {

    ssd1306_command(SSD1306_COLUMNADDR);
    ssd1306_command(0);   // Column start address (0 = reset)
    ssd1306_command(SSD1306_LCDWIDTH - 1); // Column end address (127 = reset)

    ssd1306_command(SSD1306_PAGEADDR);
    ssd1306_command(0); // Page start address (0 = reset)

    ssd1306_command(7);

    for (uint16_t i = 0; i < (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(OLED_ADDR);
      Wire.write(0x40);
      for (uint8_t x = 0; x < 16; x++) {
        Wire.write(buffer[i]);
        i++;
      }
      i--;
      Wire.endTransmission();
    }
  }

and here is the SES code for the nrf52832:

#include <stdio.h>
#include "boards.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"


#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

int err_code;

#define TWI_INSTANCE_ID     0

#define OLED_ADDR 0x3C


#define BLACK 0
#define WHITE 1
#define INVERSE 2

#define SSD1306_I2C_ADDRESS   0x3C  // 011110+SA0+RW - 0x3C or 0x3D
// Address for 128x32 is 0x3C
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)

/*=========================================================================
    SSD1306 Displays
    -----------------------------------------------------------------------
    The driver is used in multiple displays (128x64, 128x32, etc.).
    Select the appropriate display below to create an appropriately
    sized framebuffer, etc.

    SSD1306_128_64  128x64 pixel display

    SSD1306_128_32  128x32 pixel display

    SSD1306_96_16

    -----------------------------------------------------------------------*/
   #define SSD1306_128_64
//#define SSD1306_128_32
//   #define SSD1306_96_16
/*=========================================================================*/

#if defined SSD1306_128_64 && defined SSD1306_128_32
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
#error "At least one SSD1306 display must be specified in SSD1306.h"
#endif

#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH                  128
#define SSD1306_LCDHEIGHT                 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH                  128
#define SSD1306_LCDHEIGHT                 32
#endif
#if defined SSD1306_96_16
#define SSD1306_LCDWIDTH                  96
#define SSD1306_LCDHEIGHT                 16
#endif


#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF

#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA

#define SSD1306_SETVCOMDETECT 0xDB

#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9

#define SSD1306_SETMULTIPLEX 0xA8

#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10

#define SSD1306_SETSTARTLINE 0x40

#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDR 0x21
#define SSD1306_PAGEADDR   0x22

#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8

#define SSD1306_SEGREMAP 0xA0

#define SSD1306_CHARGEPUMP 0x8D

#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2

// Scrolling #defines
#define SSD1306_ACTIVATE_SCROLL 0x2F
#define SSD1306_DEACTIVATE_SCROLL 0x2E
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A


static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {

  // My buffer
  0x00, 0x00, 0x00, 0x3E, 0x7E, 0x7F, 0xE7, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3,
  0xE3, 0xFF, 0x7F, 0x7E, 0x1C, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x70, 0x38, 0x38, 0x18, 0x1C, 0x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, 0x00, 0x00, 0x0F, 0x00, 0x00,
  0x0F, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x0F, 0x08, 0x00, 0x00, 0x07, 0x0A, 0x0A, 0x0B, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x8E, 0xCE, 0xCE, 0xCE, 0xCE,
  0xCE, 0xFF, 0xFF, 0xFF, 0xFF, 0xCE, 0xCE, 0x8C, 0x0C, 0x1C, 0x1C, 0x38, 0xF8, 0xF0, 0xE0, 0x00,
  0x03, 0x07, 0x0F, 0x0E, 0x1C, 0x1C, 0x98, 0x99, 0xB9, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0xB9,
  0xB9, 0xB9, 0x38, 0x38, 0x70, 0x70, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xFC, 0x04, 0x04, 0x8C, 0xF8, 0x00, 0x00, 0x10, 0x00, 0x00, 0xFC, 0x0C,
  0x30, 0xC0, 0xC0, 0x30, 0x0C, 0xFC, 0x00, 0xF4, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x00, 0xFC,
  0x10, 0x10, 0xF0, 0x00, 0x00, 0xD0, 0x50, 0x50, 0xF0, 0x00, 0x00, 0xE0, 0x50, 0x50, 0x60, 0x00,
  0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x20, 0x20, 0x20, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0x70, 0x70, 0x38, 0x39, 0xB9, 0xB9, 0xB9,
  0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0xB9, 0x98, 0x98, 0x1C, 0x1C, 0x0E, 0x0F, 0x07, 0x03, 0x00,
  0x00, 0x00, 0x00, 0x3E, 0x3F, 0x7F, 0x73, 0x63, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3,
  0x63, 0x7F, 0x7F, 0x3F, 0x1C, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0E, 0x0E, 0x0C, 0x1C, 0x1C,
  0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x18,
  0x18, 0x19, 0x19, 0x18, 0x18, 0x19, 0x18, 0x19, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18, 0x19,
  0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x18,
  0x18, 0x19, 0x18, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x18, 0x19, 0x18, 0x18, 0x19, 0x1C, 0x1C,
  0x1C, 0x0C, 0x0E, 0x0E, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0x7F, 0x63, 0xE3,
  0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0x63, 0x7F, 0x7F, 0x3F, 0x1E, 0x00, 0x00, 0x00, 0x00,
#if (SSD1306_LCDHEIGHT == 64)
  0x1F, 0x7F, 0xFF, 0xFC, 0xF0, 0xE0, 0xC0, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x83,
  0x83, 0x83, 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x83, 0x83, 0x83, 0x83,
  0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0xC3, 0xC1, 0xC0, 0xE0, 0xF0, 0xFC, 0xFF, 0x7F, 0x1F, 0x00,
  0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x87, 0x87, 0x8F, 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x8F,
  0x8F, 0x8F, 0x0F, 0x1F, 0x3F, 0x7E, 0xFC, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x78, 0xC0, 0xC0, 0x38, 0x0C, 0xE0, 0x50, 0x50,
  0x60, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x30, 0x50, 0xD0, 0x00, 0x00, 0x00, 0xF4, 0x00, 0x00, 0xF0,
  0x10, 0x10, 0xF0, 0x00, 0x00, 0xF0, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x04, 0x04,
  0xFC, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x24, 0x24, 0x24, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xFC, 0x3E, 0x3F, 0x1F, 0x0F, 0x8F, 0x8F, 0x8F,
  0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0x8F, 0x8F, 0x87, 0x87, 0x07, 0x03, 0x01, 0x00,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0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03,
  0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x3F, 0x7F, 0x7C, 0xFC,
  0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0x7C, 0x7F, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00
#endif
#endif

};

int8_t _i2caddr, vccstate = SSD1306_SWITCHCAPVCC, sid, sclk, dc, rst, cs;

/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;

/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

/* Buffer for samples read from temperature sensor. */
static uint8_t m_sample;

/**
 * @brief Function for setting active mode on MMA7660 accelerometer.
 */
void OLED_set_mode(void)
{
    

        // Init sequence
    ssd1306_command(SSD1306_DISPLAYOFF);                    // 0xAE
    ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
    ssd1306_command(0x80);                                  // the suggested ratio 0x80

    ssd1306_command(SSD1306_SETMULTIPLEX);                  // 0xA8
    ssd1306_command(SSD1306_LCDHEIGHT - 1);

    ssd1306_command(SSD1306_SETDISPLAYOFFSET);              // 0xD3
    ssd1306_command(0x0);                                   // no offset
    ssd1306_command(SSD1306_SETSTARTLINE | 0x0);            // line #0
    ssd1306_command(SSD1306_CHARGEPUMP);

    // 0x8D

    
      if (vccstate == SSD1306_EXTERNALVCC)
      { ssd1306_command(0x10); }
      else
      {
    ssd1306_command(0x14); }
    ssd1306_command(SSD1306_MEMORYMODE);                    // 0x20
    ssd1306_command(0x00);                                  // 0x0 act like ks0108
    ssd1306_command(SSD1306_SEGREMAP | 0x1);
    ssd1306_command(SSD1306_COMSCANDEC);

#if defined SSD1306_128_32
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x02);
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    ssd1306_command(0x8F);

#elif defined SSD1306_128_64
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x12);
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    if (vccstate == SSD1306_EXTERNALVCC)
    {
      ssd1306_command(0x9F);
    }
    else
    {
      ssd1306_command(0xCF);
    }

#elif defined SSD1306_96_16
    ssd1306_command(SSD1306_SETCOMPINS);                    // 0xDA
    ssd1306_command(0x2);   //ada x12
    ssd1306_command(SSD1306_SETCONTRAST);                   // 0x81
    if (vccstate == SSD1306_EXTERNALVCC)
    {
      ssd1306_command(0x10);
    }
    else
    {
      ssd1306_command(0xAF);
    }

#endif

    ssd1306_command(SSD1306_SETPRECHARGE);                  // 0xd9
      if (vccstate == SSD1306_EXTERNALVCC)
        { ssd1306_command(0x22); }
      else
        { ssd1306_command(0xF1); }


    ssd1306_command(SSD1306_SETVCOMDETECT);                 // 0xDB
    ssd1306_command(0x40);
    ssd1306_command(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
    ssd1306_command(SSD1306_NORMALDISPLAY);                 // 0xA6

    ssd1306_command(SSD1306_DEACTIVATE_SCROLL);

    ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel
    //ssd1306_command(SSD1306_INVERTDISPLAY);
}


void ssd1306_command(uint8_t Command) {


    uint8_t control = 0x00;
    uint8_t reg[2] = {control, Command};
    err_code = nrf_drv_twi_tx(&m_twi, SSD1306_I2C_ADDRESS, reg, sizeof(reg), false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);

  }

/**
 * @brief Function for handling data from temperature sensor.
 *
 * @param[in] temp          Temperature in Celsius degrees read from sensor.
 */
__STATIC_INLINE void data_handler(uint8_t temp)
{
    NRF_LOG_INFO("Temperature: %d Celsius degrees.", temp);
}

/**
 * @brief TWI events handler.
 */
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    switch (p_event->type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                data_handler(m_sample);
            }
            m_xfer_done = true;
            break;
        default:
            break;
    }
}

/**
 * @brief UART initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_lm75b_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&m_twi);
}


void display() {

    ssd1306_command(SSD1306_COLUMNADDR);
    ssd1306_command(0);   // Column start address (0 = reset)
    ssd1306_command(SSD1306_LCDWIDTH - 1); // Column end address (127 = reset)

    ssd1306_command(SSD1306_PAGEADDR);
    ssd1306_command(0); // Page start address (0 = reset)

    ssd1306_command(7);

    for (uint16_t i = 0; i < (SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8); i++) {
      // send a bunch of data in one xmission
     err_code = nrf_drv_twi_tx(&m_twi, SSD1306_I2C_ADDRESS, buffer, sizeof(buffer), false);
     APP_ERROR_CHECK(err_code);
     while (m_xfer_done == false);
    }
  }


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("\r\nTWI sensor example");
    NRF_LOG_FLUSH();
    twi_init();


    OLED_set_mode();
    display();
    nrf_delay_ms(2000);



    while (true)
    {
        ssd1306_command(SSD1306_DISPLAYON);
        nrf_delay_ms(1000);
        ssd1306_command(SSD1306_INVERTDISPLAY);
        nrf_delay_ms(1000);

        do
        {
            __WFE();
        }while (m_xfer_done == false);

      //  read_sensor_data();
        NRF_LOG_FLUSH();
    }
}

/** @} */

/*
static void read_sensor_data()
{
    m_xfer_done = false;

    // Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. 
    ret_code_t err_code = nrf_drv_twi_rx(&m_twi, LM75B_ADDR, &m_sample, sizeof(m_sample));
    APP_ERROR_CHECK(err_code);
}

*/

trying to flash it to the nrf52832 DK for now nothing seems to work.

Thanks for your time.

  • Hi,

    You should implement the other two possible cases in your event handler too:

    NRF_DRV_TWI_EVT_DONE,         ///< Transfer completed event.
    NRF_DRV_TWI_EVT_ADDRESS_NACK, ///< Error event: NACK received after sending the address.
    NRF_DRV_TWI_EVT_DATA_NACK     ///< Error event: NACK received after sending a data byte.
    

    If your TWI bus of some reason is misbehaving you won't get a NRF_DRV_TWI_EVT_DONE event, and hence m_xfer_done will never be set to true and you will be stuck in the while loop. If you implement the other cases you can also debug and check whether your sensor responds at all. Make sure to check and double check your wiring.

  • Hi sorry for the late replay what do you mean by implementing those cases in the event handler? How should I modify the code for that?

    And yeah the wiring are correct as I've ran the I2C device scanner example and it manager to read the correct address|!

  • Expand the content of your TWI event handler from this:

    switch (p_event->type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                data_handler(m_sample);
            }
            m_xfer_done = true;
            break;
        default:
            break;
    }
    
  • to this:

    switch (p_event->type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                data_handler(m_sample);
            }
            m_xfer_done = true;
            break;
    	case NRF_DRV_TWI_EVT_ADDRESS_NACK:
    		/**************************************
    		 * Handle this case and/or check if your code hits this point with a debugger
    		 **************************************/
            break;
        case NRF_DRV_TWI_EVT_DATA_NACK:
    		/**************************************
    		 * Handle this case and/or check if your code hits this point with a debugger
    		 **************************************/
            break;
        default:
            break;
    }
    
Related