Part Number: MSP430FR2355
Other Parts Discussed in Thread: LMP90100,
Tool/software: Code Composer Studio
Hi everyone,
Could someone please help me?
I want to connect MSP430FR2355 with LMP90100 by SPI interface using the "Demo Application01 for MSP430/LMP90100 Interface Code Library v1.0" code. I'm trying to write 0x83 value to 0x11 register but MISO returns 0x00 all the time. I know that I'm missing something but I don't know what it is.
Connections: 3.3V -------------------------------> VDD3P3 (JP12.13)
GND ------------------------------> GND (JP12.2)
GND ------------------------------> GND (J8)
UCA0CLK (P1.5) --------------> SCLK (J8)
UCA0SOMI (P1.6) ------------> SDO_DRDYB (J8)
UCA0SIMO (P1.7) ------------> SDI (J8)
CS (P2.0) ------------------------> CSB (J8)
P2.2 -------------------------------> D6_DRDYB (JP8)
Code:
#include <msp430.h>
#include <stdint.h>
#define LMP90100_URA_END (0xFF)
#define LMP90100_URA_MASK (0x70)
#define LMP90100_LRA_MASK (0x0F)
#define LMP90100_READ_BIT (0x80)
#define LMP90100_WRITE_BIT (0x00)
#define LMP90100_SIZE_1B (0x00)
#define LMP90100_INSTRUCTION_BYTE1_WRITE (0x10)
#define TI_LMP90100_SPI_DRDYBCN_REG_VALUE (0x83) /* Enable DRDYB on D6, bits 0 & 1 must be 1, others default */
#define TI_LMP90100_SPI_DRDYBCN_REG (0x11) /* SPI Data Ready Bar Control */
uint8_t prev_URA;
uint8_t reg_write_data, reg_read_data;
void TI_LMP90100_WriteRegSettings(uint8_t *); // Configure LMP90100 registers
uint8_t addr, i;
//------------------------------------------------------------------------------
// void TI_LMP90100_SPIWriteReg(uint8_t addr, uint8_t value, uint8_t *pURA)
//
// DESCRIPTION:
// Writes "value" to a single configuration register at address "addr". If
// "addr" lies within the same segment as "*pURA", it takes 1 less transaction
// to write the value.
//------------------------------------------------------------------------------
void TI_LMP90100_SPIWriteReg(uint8_t addr, uint8_t value, uint8_t *pURA)
{
uint8_t new_URA, inst;
new_URA = (addr & LMP90100_URA_MASK)>>4; // extract upper register address
P2OUT &= ~BIT0; // /CS enable
if (*pURA != new_URA) // if new and previous URA not same, add transaction 1
{
inst = LMP90100_INSTRUCTION_BYTE1_WRITE; // Transaction-1
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = inst; // Send instruction
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = new_URA; // Send upper register address
*pURA = new_URA; // save new URA
}
inst = LMP90100_WRITE_BIT | LMP90100_SIZE_1B |(addr & LMP90100_LRA_MASK); // lower register address
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = inst; // Send lower register address
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = value; // Send data value
while (UCA0STATW & UCBUSY); // Wait for TX complete
P2OUT |= BIT0; // /CS disable
}
//------------------------------------------------------------------------------
// uint8_t TI_LMP90100_SPIReadReg(uint8_t addr, unit8_t *pURA)
//
// DESCRIPTION:
// Reads a single configuration register at address "addr" and returns the
// value read. If "addr" lies within the same segment as "*pURA", it takes 1
// less transaction to read the value.
//------------------------------------------------------------------------------
uint8_t TI_LMP90100_SPIReadReg(uint8_t addr, uint8_t *pURA)
{
uint8_t x, new_URA, inst;
new_URA = (addr & LMP90100_URA_MASK)>>4; // extract upper register address
P2OUT &= ~BIT0; // /CS enable
if (*pURA != new_URA) // if new and previous URA not same, add transaction 1
{
inst = LMP90100_INSTRUCTION_BYTE1_WRITE; // Transaction-1
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = inst; // Send instruction
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = new_URA; // Send upper register address
*pURA = new_URA; // save new URA
}
inst = LMP90100_WRITE_BIT | LMP90100_SIZE_1B | (addr & LMP90100_LRA_MASK); // Transaction-2
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = inst; // Send lower register address
while (!(UCA0IFG&UCTXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0; // Dummy write so we can read data
while (UCA0STATW & UCBUSY); // Wait for TX complete
while (!(UCA0IFG&UCRXIFG));
x = UCA0RXBUF; // Read data
P2OUT |= BIT0; // /CS disable
return x;
}
void LMP90100_SPISetup(void)
{
P2OUT |= BIT0;
P2DIR |= BIT0; // /CS disable
UCA0CTLW0 |= UCSWRST; // **Disable USCI state machine**
UCA0CTLW0 |= UCMST|UCSYNC|UCCKPL|UCSTEM|UCMSB|UCMODE_2;
UCA0CTLW0 |= UCSSEL_2; // SMCLK
UCA0BRW = 0x10; // UCLK/16
UCA0MCTLW = 0;
UCA0IE |= UCRXIE;
UCA0IE |= UCTXIE;
P1SEL0 |= BIT7 | BIT6; // SIMO P1.7, SOMI P1.6
P1SEL0 |= BIT5; // CLK P1.5
// SPI option select
P1DIR |= BIT7 | BIT5; // SPI TXD out direction
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
P1OUT |= BIT0; // Set LED ON
P1DIR |= BIT0; // Set pin direction is output
LMP90100_SPISetup(); // Initilaize MSP430 SPI Block
prev_URA = LMP90100_URA_END; // Initialize prev_URA to invalid segment
reg_write_data = TI_LMP90100_SPI_DRDYBCN_REG_VALUE; // value to write
TI_LMP90100_SPIWriteReg(TI_LMP90100_SPI_DRDYBCN_REG, reg_write_data, &prev_URA); // Write to SPI_DRDYBCN register
reg_read_data = TI_LMP90100_SPIReadReg(TI_LMP90100_SPI_DRDYBCN_REG, &prev_URA); // Read back the value written
// test if write/read values match
if (reg_write_data == reg_read_data)
{
while (1) // no error: blink LED continuously
{
__delay_cycles(250000);
__delay_cycles(250000);
P1OUT ^= BIT0;
}
} else
{
P1OUT &= ~BIT0; // error: Set LED OFF
}
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
__no_operation(); // For debugger
}
Thanks,
Mikel