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.

MSP430F2274: Parameterization Question

Part Number: MSP430F2274

Hi,

I would like to find out how to go about parameterizing one of these tags. For example, what would be the right way to turn this:

void tx(unsigned char txbyte) //This routine transmits a byte from UCA0
{

UCA0TXBUF = txbyte;
}

into something more like this:

void tx(unsigned char txbyte, some data type transmitBuffer) //This routine transmits a byte from UCA0
{

transmitBuffer = txbyte;
}

so that I could call the tx function like this:

tx(0x11, UCA0TXBUF);

I would like to have this function in a file which will be shared between different variants of MSP430s which may have different #define names for transmit buffers and other registers.

  • They are just addresses, so a pointer should work, void * should be width agnostic. Note that you will have none of the error checking, so you can create some marvelous bugs. You also might have to cast to a pointer of the correct width.

    This is one of those "try it and keep changing things until the errors go away" things.

  • Hello Ryan,

    I would just like to point out that we do offer higher-level, abstracted software for some MSP430 family.  It's called DriverLib. And we have the MSPM0SDK for the new M0 devices.  You can try looking at the API guide for the FR2xx_4xx devices, most are configured kind of like what you describing, where you actually pass a base address for the peripheral you're using, and then it automatically uses the offset to access the related registers it wants.  

    Unfortunately, we do not have a driverlib for F2xx devices.  

    Good luck with your project.

    Thanks,

    JD

  • I could not figure out how to pass the base address successfully so I wound up doing using pointers. 
    I am making a generic file which can be used for different msp430 series chips, so the generic file contains something like:

    volatile unsigned char *txBufferPtr; void setBuffers(volatile unsigned char txBufferAddress) { txBufferPtr = txBufferAddress; } void tx(unsigned char txByte) { *txBufferPtr = txByte; // plus additional code to wait until transmit flag changes state } In the main program in the project-specific file, I call setBuffers(&UCA0TXBUF); once at startup, then the tx(); function works as intended. I also did similar for rx buffer and associated flags.

**Attention** This is a public forum