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.

MSP430F2416: Reading a 24 bit register by using SPI

Part Number: MSP430F2416
Other Parts Discussed in Thread: AFE4490

Hi all,

I have tried to read  the 24 bit register of AFE4490 through SPI,How can I effectively done this, I have tried the following method please help to resolve this out.

unsigned long AFE4490_Reg_Read(unsigned char reg_address)
{

P1OUT &= ~ BIT4;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = reg_address;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff1= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff2= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff3= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff4= UCA1RXBUF;

P1OUT |= BIT4;

retValue = (SPI_Rx_buff4|(SPI_Rx_buff3<<8)|(SPI_Rx_buff2<<16));

return retValue;

}

  • > retValue = (SPI_Rx_buff4|(SPI_Rx_buff3<<8)|(SPI_Rx_buff2<<16));

    My first guess is that SPI_Rx_buffX are declared uint8_t (or unsigned char), so they're not surviving the shifts. Try:

    > retValue = ((unsigned long)SPI_Rx_buff4|((unsigned long)SPI_Rx_buff3<<8)|((unsigned long)SPI_Rx_buff2<<16));

    (or you can use uint32_t instead of "unsigned long" if you've got it).