This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-F28379D: NHD-0420CW-AG3, Serial Communication (I2C, SPI). Library?

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE

Hi,

I'm looking to run the NHD-0420CW-AG3, OLED display, using the F28379D LaunchPad. I want to use SPI or I2C to communicate. Is there a library for running an OLED screen via I2C or SPI communication? Maybe there is an easy work around to do this using a library for an LCD screen?

Another way of solving this problem is using some sample code NHD wrote for this screen. The only issue is they used an Arduino as their micro controller and I'm unsure how to work this into the CCS language. Is there a way to easily convert the Arduino code to be used on the F28379D? Mainly looking for how to implement the command, data and putData functions used in the code from the github link below.

https://github.com/NewhavenDisplay/NHD-0420CW-Slim-OLED

Any help would be greatly appreciated.

Thank you,

Ryan

  • Hello Ryan,

    Is there a library for running an OLED screen via I2C or SPI communication? Maybe there is an easy work around to do this using a library for an LCD screen?

    I am not aware of any C2000 code for that specific display. You'll have to create something specific to C2000 using the Arduino code as reference. I would suggest you start from a C2000ware SPI example.

    Mainly looking for how to implement the command, data and putData functions used in the code from the github link below.

    You can use the code I wrote in the post below as a reference of how to use the SPI module on the C2000 device to send commands and data to the display. 

    https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/893612/tms320f28379d-c2000-communicates-with-lcd-by-spi/3307824?tisearch=e2e-sitesearch&keymatch=sharp%252525252520spi%252525252520example%252525252520martinez#3307824 

  • Gus,

    I've been working with your example code to get a working SPI transmission. For the purposes of this exercise I am connecting the SPICLKB and SPISOMIB to my oscilloscope to verify it is sending the correct lines through the sendData command.

    Currently I am reading static. There is not clear data or clock transmission happening. Would you be able to take a look at my code below?

    Thanks,

    Ryan

    #define DEVICE_GPIO_PIN_SPISIMOB     63  // GPIO number for OLED_SPIMOSIB
    #define DEVICE_GPIO_CFG_SPISIMOB     GPIO_63_GPIO63    // "pinConfig" for OLED_SPIMOSIB

    #define DEVICE_GPIO_PIN_SPISOMIB     64  // GPIO number for OLED SPIMISOB
    #define DEVICE_GPIO_CFG_SPISOMIB     GPIO_64_GPIO64  // "pinConfig" for OLED_SPIMISOB

    #define DEVICE_GPIO_PIN_SPICLKB      65  // GPIO number for OLED_CLK
    #define DEVICE_GPIO_CFG_SPICLKB      GPIO_65_GPIO65  // "pniConfig" for OLED_CLK

    void SPI_sendData(uint16_t data)
    {
        uint16_t volatile dummy = 0;
        //Send the command via SPI:
        SPI_writeDataBlockingNonFIFO(SPIB_BASE, data);
        dummy = SPI_readDataBlockingNonFIFO(SPIB_BASE); //dummy read to clear INT_FLAG
    }

    void initSPI()
    {
        //
        // Must put SPI into reset before configuring it.
        //
        SPI_disableModule(SPIB_BASE);

        //
        // SPI configuration. Use a 1MHz SPICLK and 8-bit word size.
        //
        SPI_setConfig(SPIB_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA1,
                      SPI_MODE_MASTER, 1000000, 8);
        SPI_enableLoopback(SPIB_BASE);
        SPI_setEmulationMode(SPIB_BASE, SPI_EMULATION_STOP_AFTER_TRANSMIT);

        //
        // Configuration complete. Enable the module.
        //
        SPI_enableModule(SPIB_BASE);
    }

    void main(void)
    {

    Device_init();

        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();

        //
        // Initialize GPIOs on LaunchPad for OLED SPI and control pins
        //
        // OLED_SPI_MOSI
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPISIMOB,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPISIMOB);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPISIMOB,GPIO_QUAL_ASYNC);

        // OLED_SPI_MISO
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPISOMIB,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPISOMIB);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPISOMIB,GPIO_QUAL_ASYNC);

        // OLED_SPI_CLK
        GPIO_setPadConfig(DEVICE_GPIO_PIN_SPICLKB,GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(DEVICE_GPIO_CFG_SPICLKB);
        GPIO_setQualificationMode(DEVICE_GPIO_PIN_SPICLKB,GPIO_QUAL_ASYNC);

    //
        // Initialize the SPI
        //
        initSPI();

     while(1)
        {
            SPI_sendData('H');
            SPI_sendData('e');
            SPI_sendData('l');
            SPI_sendData('l');
            SPI_sendData('o');
            SPI_sendData(' ');
            SPI_sendData('w');
            SPI_sendData('o');
            SPI_sendData('r');
            SPI_sendData('l');
            SPI_sendData('d');
            SPI_sendData('!');
        }
    }

  • Ryan,

    I believe it's your SPI pinmux configuration. Here you need to specify the pin and pinmux function. Right now you have these pins set as GPIO, not SPI. 

    #define DEVICE_GPIO_PIN_SPISIMOB     63  // GPIO number for OLED_SPIMOSIB
    #define DEVICE_GPIO_CFG_SPISIMOB     GPIO_63_GPIO63    // "pinConfig" for OLED_SPIMOSIB
    
    #define DEVICE_GPIO_PIN_SPISOMIB     64  // GPIO number for OLED SPIMISOB
    #define DEVICE_GPIO_CFG_SPISOMIB     GPIO_64_GPIO64  // "pinConfig" for OLED_SPIMISOB
    
    #define DEVICE_GPIO_PIN_SPICLKB      65  // GPIO number for OLED_CLK
    #define DEVICE_GPIO_CFG_SPICLKB      GPIO_65_GPIO65  // "pniConfig" for OLED_CLK

    Here is what I think it should be.

    #define DEVICE_GPIO_PIN_SPISIMOB     63  // GPIO number for OLED_SPIMOSIB
    #define DEVICE_GPIO_CFG_SPISIMOB     GPIO_63_SPISIMOB    // "pinConfig" for OLED_SPIMOSIB
    
    #define DEVICE_GPIO_PIN_SPISOMIB     64  // GPIO number for OLED SPIMISOB
    #define DEVICE_GPIO_CFG_SPISOMIB     GPIO_64_SPISOMIB  // "pinConfig" for OLED_SPIMISOB
    
    #define DEVICE_GPIO_PIN_SPICLKB      65  // GPIO number for OLED_CLK
    #define DEVICE_GPIO_CFG_SPICLKB      GPIO_65_SPICLKB  // "pniConfig" for OLED_CLK

  • Btw, for the chip select, you have the option of letting the SPIB drive the pin directly (pinConfig => GPIO_66_SPISTEB) or you can have the CPU control that pin directly (pinConfig => GPIO_66_GPIO66) through normal GPIO writes. Typically the CPU/GPIO method is more flexible since you can more easily control the amount of SPI data per chip select pulse.

  • Gus,

    Thank you, this solved half the issue. I am now getting a correct clock signal. However, the MOSI signal is still garbage, static at ~0V on the oscilloscope. Any thoughts? Would it be more likely the issue is in my initSPI or in the GPIO setup in my main or is it something else entirely?

    Also, thanks for the pointer on the \CS pin, good to know there are options once I get to that.

    Thanks again,

    Ryan

  • Ryan,

    You have loopback mode enabled. Try disabling that and the MOSI pin should become active. 

  • Gus,

    Sadly, that didn't fix the issue. Getting the same output with and without loop back enabled.

  • When I zoom in on the output I get ' from my decoder. Rather than the expected message.

  • I missed that you were using 8-bit character size. The SPIDAT register is a shift register, where the MSB gets shifted out first. You have to left-shift your data to the top byte of the 16-bit register (<<8).

  • We're getting closer! I'm seeing all of the letters I am putting into the register, but there are extra characters being sent.

  • Can you expand a little more on what you are seeing?

  • I just switched over from SPIB to SPIA and kept everything else the same. Adjusted the scope to read off of the correct pins and it now appears to be working correctly.

    Did the same thing switching back to SPIB and that works correctly now! weird that it wasn't before. Probably had a typo. Thanks for all the time and help! Have a nice weekend!

  • The difference that was causing this most recent issue was related to the oscilloscope I was reading off of. When I randomly changed the period to 50us it suddenly read the data correctly. Still running at 1MHz from the uController. I'm only seeing 43 messages. I would have expected closer to 50. Do you know why I'm reading correctly at this period and not others? At a shorter period I would expect to still see the correct data, just fewer messages. At any period, the scope is running at the same frequency and taking the same number of samples per second. Any ideas?

  • At 1MHz SCLK rate the clock period is 1uS. A character of 8-bits will take approximately 8us to transmit. To see a full 50 characters (I'm assuming this is what you mean by messages) you would need to capture at least 400us on the scope. There is probably a time gap between characters since you are not using FIFO mode on the SPI configuration. Therefore likely you will need more than 400us. I hope this helps!