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.

MSP430F5529:

Part Number: MSP430F5529
Other Parts Discussed in Thread: LMX2595

Hello Everyone. In my Application I have made use of MSP430F5529 to transfer 79-registers data which is of 24-bit long to slave device LMX2595. So Initially I have broken the 24-bit data into three 8 bytes and stored into an array. Later I have used pointer to access the data which is in the array. 

I will be attaching the code below, which was implemented in non-state machine mode and I haven't kept the complete array elements below . I am working so long but unable to complete this code. Any help would be greatly  appreciated

1) Can anyone help me out in implementing state machine mode as the slave device Doesn't acknowledge any data instead it just performs Echoing the data using mux out pin which was transmitted by MSP430F5529 controller.

2) As of Now I have MSP430F5529 Launchpad kit. How do I check this stream of data once the code is been dumped to launchpad. 

#include <msp430.h> 
#include <stdint.h>
#include <stdbool.h>

#define DUMMY 0xFF

#define SLAVE_CS_OUT P2OUT
#define SLAVE_CS_DIR P2DIR
#define SLAVE_CS_PIN BIT0

#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

#define TYPE_0_LENGTH 1
#define TYPE_1_LENGTH 2
#define TYPE_2_LENGTH 6

#define MAX_BUFFER_SIZE 237

/
uint8_t MasterType0[TYPE_0_LENGTH] = {0x11};
uint8_t MasterType1[TYPE_1_LENGTH]= {8, 9};
uint8_t MasterType2[TYPE_2_LENGTH] = {'F', '4' , '1' , '9', '2', 'B'};

uint8_t SlaveType0[TYPE_0_LENGTH] = {0};
uint8_t SlaveType1[TYPE_1_LENGTH] = {0};
uint8_t SlaveType2[TYPE_2_LENGTH] = {0};

/*
* LMX2595 specific data
*/
const uint8_t register_values[237] = {0x00,0x25,0x1C,
0x01,0x08,0x08,0x02,0x05,0x00,0x03,0x06,0x42,0x04,0x0A,0x43,0x05,0x00,0xC8,0x06,0xC8,0x02,0x07,0x40,0xB2,0x08,0x20,0x00,0x09,0x16,0x04,0x0A,0x10,0xD8,0x0B,0x00,0x18,0x0C,0x50,0x01,0x0D,0x40,0x00,0x0E,0x1E,0x40,0x0F,0x06,0x4F,0x10,0x00,0x80,0x11,0x01,0x2C,0x12,0x00,0x64,0x4E,0x00,0x03};

// General SPI State Machine **

typedef enum SPI_ModeEnum{
IDLE_MODE,
TX_REG_ADDRESS_MODE,
RX_REG_ADDRESS_MODE,
TX_DATA_MODE,
RX_DATA_MODE,
TIMEOUT_MODE
} SPI_Mode;


uint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0};
uint8_t RXByteCtr = 0;
uint8_t ReceiveIndex = 0;
uint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0};
uint8_t TXByteCtr = 0;
uint8_t TransmitIndex = 0;


SPI_Mode SPI_Master_WriteReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count);


* 24 bit data sending routine
void SPI_Master_Write_24bits(uint8_t *reg_data, uint8_t count);

SPI_Mode SPI_Master_ReadReg(uint8_t reg_addr, uint8_t count);
void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count);
void SendUCA0Data(uint8_t val);

void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count)
{
uint8_t copyIndex = 0;
for (copyIndex = 0; copyIndex < count; copyIndex++)
{
dest[copyIndex] = source[copyIndex];
}
}


SPI_Mode SPI_Master_WriteReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
MasterMode = TX_REG_ADDRESS_MODE;
TransmitRegAddr = reg_addr;

//Copy register data to TransmitBuffer
CopyArray(reg_data, TransmitBuffer, count);

TXByteCtr = count;
RXByteCtr = 0;
ReceiveIndex = 0;
TransmitIndex = 0;

SLAVE_CS_OUT &= ~(SLAVE_CS_PIN);
SendUCA0Data(TransmitRegAddr);

__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts

SLAVE_CS_OUT |= SLAVE_CS_PIN;
return MasterMode;
}

/*
* NON STATE MACHINE IMPLEMENTATION
*/
void SPI_Master_Write_24bits(uint8_t *reg_data, uint8_t count)
{
TXByteCtr = count;
RXByteCtr = 0;
ReceiveIndex = 0;
TransmitIndex = 0;

SLAVE_CS_OUT &= ~(SLAVE_CS_PIN);

while(TXByteCtr > 0)
{
SendUCA0Data(*reg_data);
reg_data++;
TransmitIndex++;
TXByteCtr--;
if((TransmitIndex%3 == 0)&&(TransmitIndex>0))
{
SLAVE_CS_OUT |= SLAVE_CS_PIN; // CS pin pulled high after every 3 bytes sent
_delay_cycles(2000000); // adjust if needed
SLAVE_CS_OUT &= ~SLAVE_CS_PIN; // for next byte
}


}

}

SPI_Mode SPI_Master_ReadReg(uint8_t reg_addr, uint8_t count)
{
MasterMode = TX_REG_ADDRESS_MODE;
TransmitRegAddr = reg_addr;
RXByteCtr = count;
TXByteCtr = 0;
ReceiveIndex = 0;
TransmitIndex = 0;

SLAVE_CS_OUT &= ~(SLAVE_CS_PIN);
SendUCA0Data(TransmitRegAddr);

__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts

SLAVE_CS_OUT |= SLAVE_CS_PIN;
return MasterMode;
}


void SendUCA0Data(uint8_t val)
{
while (!(UCA0IFG & UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = val;
}

 

Thanks in Advance

**Attention** This is a public forum