Using SPI2 to Control OLED display on the BasicIO board (from chipkit WiFire)

This topic contains 1 reply, has 2 voices, and was last updated by  Noell 6 days, 10 hours ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #53848

    Amit
    Member

    I recently had a problem in programming the OLED display to interactively position the cursor on a line/column and display characters starting at that position.
    This required changing the Data/#CMD signal: #CMD-to set the cursor position; Then Data-to display characters

    Setting the cursor position involves setting the PAGE (0xB0 command) and then setting the Column (0x0 + 0x10 commands). My implementation wouldn’t correctly set the cursor position.

    Here is the code segment I used for sending a byte over SPI2 to the OLED:
    void Spi2PutByte(BYTE bVal)
    {
    // Wait for transmitter to be ready
    while (SPI2STATbits.SPITBE == 0)
    ;

    // Write the next transmit byte.
    SPI2BUF = bVal;

    // Wait for Transmitter to Empty out
    while (SPI2STATbits.SPITBE == 0)
    ;

    }

    The problem turned out to be that this routine waits for the sent byte to clear the Transmitter register — but that happens immediately when the byte loads into the shift-register. However, the byte still hasn’t shifted out. Therefore, my routine returned too early and changed the Data/#CMD control signal while the previous byte was “mid-flight”.

    Thanks to Digilent support engineer Andrew Holzer for finding this.

    There are two possible fixes for this:

    1. Monitor the SPI2 SPIBUSY bit before exiting the routine. As such:
    void Spi2PutByte(BYTE bVal)
    {
    // Wait for transmitter to be ready
    while (SPI2STATbits.SPITBE == 0)
    ;

    // Write the next transmit byte.
    SPI2BUF = bVal;

    // Wait for SPI function to complete
    while (SPI2STATbits.SPIBUSY)
    ;

    }

    or

    2. Wait for the in-coming byte to be received (but this requires a dummy read of the SPI2BUF to clear the receiver status bit) as thus:

    void Spi2PutByte(BYTE bVal)
    {
    // Wait for transmitter to be ready
    while (SPI2STATbits.SPITBE == 0)
    ;

    SPI2BUF ; //Dummy read of SPI buffer to clear RCV status bits

    // Write the next transmit byte.
    SPI2BUF = bVal;

    // Wait for Receiver to get incoming byte
    while (SPI2STATbits.SPIRBF == 0)
    ;
    }

    #56691

    Noell
    Member

    Hi..as per my understanding you should follow this–> Go to the chipKIT Basic I/O Shield homepage mentioned in the reference section. Download the zip file that contains libraries and documentation for using the Basic I/O Shield™ with the chipKIT MPIDE. Open the downloaded zip folder and copy the three IOShield folders in it. These three folders have the libraries and example programs for EEPROM, OLED and Temperature Sensor peripherals on IO shield.

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.