I need help communicating with the Sparkfun 7-Segment Serial Display using I2C

16 Dec 2013

Datasheet: https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Serial-7-Segment-Display-Datasheet

Below is how I hooked up my pullup resisters to the corresponding mbed I2C pins and jumper wires

+ = positive side of my breadboard

+ -> mbed Vout

+ -> 2.2k -> p9 and Jumper-wire in the same breadboard hole -> Jumper wire -> SDA pin on Sparkfun 7-Segment Serial Display

+ -> 2.2k -> p10 and Jumper-wire in the same breadboard hole -> Jumper wire -> SCL pin Sparkfun 7-Segment Serial Display

CODE:

#include "mbed.h"

DigitalOut myled(LED1);

I2C i2c(p9, p10);

const int addr = 0x71; //7-Segment Serial display is 0x71

int main() {
    char cmd[4]; //[0x31][0x32][0x41][0x42] (ASCII-code for '1', '2', 'a', 'b')
    
    cmd[0] = 0x31;
    cmd[1] = 0x32;
    cmd[2] = 0x41;
    cmd[3] = 0x42;
    
    i2c.write(addr, cmd, 4);
    
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

My design is not working as expected. The Sparkfun 7-segment board is not showing any values that I am attempting to output with the mbed via i2c. I have never used i2c before so I am not sure if my pullup resister is correctly hooked up and if my code is properly outputting the bytes to the display.

To debug my design I checked if the display is getting power which it is. I used UART which also worked as expected by correctly outputting ASCII to the display.

I have no idea why the i2c communication is not working, what do I need to get my i2c communication to work?

17 Dec 2013

The mbed libs use the 8bit i2c address mode. You have used the 7bit mode given in the arduione example code. So instead of 0x71 the slave addres should be defined as 0xE2. The address has been shifted left by one bitposition. It also seems that the supplyvoltage for the display should be 5V rather than 3V3. Please check the datasheet and use mbed Vu in that case.

17 Dec 2013

I think you need to have:

Address (physical of device) ( Address of first register to write to, Data [1, 2, ...n, n+1] )

For my MCP230017, this appears to work..

NOTE: The address to write to is the first byte of the array.

I have had a quick look through the datasheets, but it is a little vague.

have you looked at the example code ??

Cheers

Ceri

20 Dec 2013

Wim Huiskamp wrote:

The mbed libs use the 8bit i2c address mode. You have used the 7bit mode given in the arduione example code. So instead of 0x71 the slave addres should be defined as 0xE2. The address has been shifted left by one bitposition. It also seems that the supplyvoltage for the display should be 5V rather than 3V3. Please check the datasheet and use mbed Vu in that case.

wim, When you explained to me about the slave address should be defined as 0xE2, do you mean to also change the slave's internal bit address value to 0xE2 along with the bit address in my code?

ceri clatworthy wrote:

I think you need to have:

Address (physical of device) ( Address of first register to write to, Data [1, 2, ...n, n+1] )

For my MCP230017, this appears to work..

NOTE: The address to write to is the first byte of the array.

I have had a quick look through the datasheets, but it is a little vague.

have you looked at the example code ??

Cheers

Ceri

Ceri, I don't understand what you mean by

Address (physical of device) ( Address of first register to write to, Data [1, 2, ...n, n+1] )

Also, I have looked at the i2c example code from mbed handbook and from sparkfun's 7 segment display example code

20 Dec 2013

Quote:

When you explained to me about the slave address should be defined as 0xE2, do you mean to also change the slave's internal bit address value to 0xE2 along with the bit address in my code?

According to the datasheet the default I2C slaveaddress is 0xE2. So you dont need to change that if it has not been modified. You could change it to allow more than one display on the same I2C bus. Note that all slaves must have a unique slaveaddress. You should have only device on your bus that responds to the defaultaddress when you try to change this address.

Assuming that the display is using the default address, the code below should work:

#include "mbed.h"
 
DigitalOut myled(LED1);
 
I2C i2c(p9, p10);
 
const int addr = 0xE2; //7-Segment Serial display default address is 0xE2 (8 bit format, mbed compatible)
 
int main() {
    char cmd[4]; //[0x31][0x32][0x41][0x42] (ASCII-code for '1', '2', 'a', 'b')
    
    cmd[0] = 0x31;
    cmd[1] = 0x32;
    cmd[2] = 0x41;
    cmd[3] = 0x42;
    
    i2c.write(addr, cmd, 4);
    
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
} 

The comment by Ceri refers to some other types of I2C slaves that commonly use an internal register that must be selected first before sending any data. That registeraddress is always the first byte following the slaveaddress. Subsequent bytes are then stored starting from the selected register. This particular display does not use that method. It does however respond to certain databytes which are then interpreted as commands. For example databyte 0x76 (character 'v') wil clear the display.