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.

MSP430FR2355: How to create an undefined/variable array

Part Number: MSP430FR2355

Hi Team,

We would like to ask your help regarding the customer's concern below.

I am struggling with an interrupt vector. I obtained a sample code for I2C transmit from master to slave. This code uses an interrupt service routine to send a data array to a transmit buffer. For this to work the data array has to be declared as a global.

When you have multiple devices on the i2c bus you will likely end up with multiple different arrays which need to be piped through the data array to the transmit buffer.

How do I create an undefined/variable array which I can use to pass other different size arrays to? This undefined array is part of the tx interrupt vector of the i2c which passes it data to the tx buffer.

I am looking for a simple structure. If I define the array size to a specific size the transmit buffer will sent all the elements. I am of course only interested in sending the elements with the required data in them.

Thank you for your support!

Regards,

Danilo

  • Hello,

    I think the customer is asking if they can dynamically size an array. While it may be possible, I wouldn't recommend it. In our I2C code examples, you'll see there are several arrays of different sizes. This way, depending on the command, the appropriate array size can be used without having to size it dynamically.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    //******************************************************************************
    // Example Commands ************************************************************
    //******************************************************************************
    #define SLAVE_ADDR 0x48
    /* CMD_TYPE_X_SLAVE are example commands the master sends to the slave.
    * The slave will send example SlaveTypeX buffers in response.
    *
    * CMD_TYPE_X_MASTER are example commands the master sends to the slave.
    * The slave will initialize itself to receive MasterTypeX example buffers.
    * */
    #define CMD_TYPE_0_SLAVE 0
    #define CMD_TYPE_1_SLAVE 1
    #define CMD_TYPE_2_SLAVE 2
    #define CMD_TYPE_0_MASTER 3
    #define CMD_TYPE_1_MASTER 4
    #define CMD_TYPE_2_MASTER 5
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • The way I dealt with this is to simply pass a pointer to the data string and its length. The I2C transmit routine then dealt with the details.

    Dynamically sizing the arrays is of courses possible using malloc() and free() but is not recommended for embedded systems. Unless you are very very sure that you will never run out of heap space and you don't have any leaks.

**Attention** This is a public forum