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.

CCS/MSP430FR2433: How to point the memory address of a slave I2C device to read bytes from

Part Number: MSP430FR2433


Tool/software: Code Composer Studio

Hello I am a newbie in programming MSP430, specifically for the I2C interface.

I were snipping in some source programs that come in CCS Toolkit and found good examples of two MSP430 boards talking one with other in a I2C Master/Slave and the Master receiving some bytes of information from the slave.

I have a Slave I2C device (IC sensor) that i need to read 128 bytes starting from the address 0x80, the Master will be the MSP430FR2433.

In the examples I've seen, i haven't found how to tell the slave that i want the information starting for example from 0x80. I also have doubt if there is some other parameter o read routine that requests the amount of memory to read or if I need to do a loop interaction 128 times in this case. 

Do you have some example on how to do this ?

I will appreciate your help.

Flavio

 

  • This information would be in your slave device's data sheet. A common model is a register array, where you "write" a register index, then "read" one or more consecutive array elements. But not all slave devices work this way.

  • Hello Bruce, thank you for the reply.

    I'm already able to talk with the device but using Python in a RapberryPI.

    My main doubt is how to specify in C, which is the starting address to read from the slave I2C device using the CSS libraries. 

    I saw in the samples only the way you specify the device address and frequency, but not one that shows how to specify the initial address to read in the slave.

    Best regards,

    Flavio

  • Just to be more clear regarding my last post.

    This is the code found as a sample for the I2C master talking with another board acting as a slave that reply with data from address 0, i don't see where you designate the start address to read from the slave I2C, in ths case maybe because it is from address 0 ther is no need to configure, but I would like to know how to indicate that the data will come strarting from the address 0x80.

        // Configure USCI_B0 for I2C mode

        UCB0CTLW0 |= UCSWRST;                   // Software reset enabled

        UCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C mode, Master mode, sync

        UCB0CTLW1 |= UCASTP_2;                  // Automatic stop generated

                                                // after UCB0TBCNT is reached

        UCB0BRW = 0x0008;                       // baudrate = SMCLK / 8

        UCB0TBCNT = 0x0040;                     // number of bytes to be received = 64

        UCB0I2CSA = 0x0048;                     // Slave address

        UCB0CTL1 &= ~UCSWRST;

        UCB0IE |= UCRXIE | UCNACKIE | UCBCNTIE

  • You haven't said whether your slave device uses the "register array" model. If it doesn't none of the following applies.

    In the usual register-array model, the register number is first written as data (either 8 bits or 16 bits, check the data sheet) and then stops. The device remembers this number, then the next read retrieves data from the register array starting at that index, incrementing the index on each byte.

    A register-write also sends the register number (as data), but then it doesn't stop, rather it sends more data to be written into consecutive registers (again, the slave increments the index as it goes).

    ---------------------------------------------------------

    If you're looking at msp430fr243x_eusci_i2c_standard_master.c, I think you have the pieces, though it may not be obvious. This program has the concepts of "commands" and "types", but they're really just names for "register number" and "data length". If you want to e.g. read 3 registers, starting with register 5, I'm pretty sure you can just

    > I2C_Master_ReadReg(SLAVE_ADDR, 5, 3);   // Read registers 5,6,7

    and the result will come back in ReceiveBuffer[]. Similarly, you can write register 4  as 0x55 with

    > uint8_t register_4_new_contents[1] = {0x55};

    > I2C_Master_WriteReg(SLAVE_ADDR, 4, register_4_new_contents, sizeof(register_4_new_contents)); // Write register 4 with 0x55

    This program assumes that register numbers are 8 bits, not 16 bits. Check the data sheet to make sure that's OK.

**Attention** This is a public forum