cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting the AIS2IH accelerator with TI microcontrollers like the MSP430FR2532 via SPI Interface

Ni
Associate

I am working on a project to connect the AIS2IH accelerator with the MSP430FR2532 board for an motion detection product. I had decided to use the SPI bus interface to connect the two devices. The hardware connection are as follows:

 

MSP430AIS2IHSPI meaning
P2.2CS(AIS2IH specific?)
P1.1/ USB0CLKSPCSCLK
P1.2/UCB0SIMOSDISIMO
P1.3/UCB0SOMISDOSOMI


For the SPI set up on the MSP430 board:

1. Set the to send Most Significant Bit first based on AIS2IH SPI requirement
2. The Clock Polarity is set high as the clock when inactive must be high
3. Similarly when there is no SPI operation P2.2 is set high and for a SPI operation P2.2 is set low
4. The Clock is turned off prior to setting a the P2.2 -> low. I had done this because as per my understanding regardless of the clock state or power mode in the MSP430, the clocks are set to active state for peripheral operations(From section 3.2.12 in MSP430FR2xx family user guide)

When trying to use the ais2ih driver to identify if the device is connected, I get a false output. The ais2ih_device_id_get(&dev_ctx, &whoamI); give the whomI value to be 0x00

Could someone help me solve this and point me in the right direction to interface these 2 devices. I have attached my code below:

 

 

 

#include <msp430.h>
#include "ais2ih_reg.h"

int main() {
    GPIO_Init();
    SPI_Init();
    __delay_ms(BOOT_TIME); //Say 20 ms
    Ais2ih_device();
}

void GPIO_Init(void){
    P2OUT |= BIT2;
    P2DIR |= BIT2;
    P2SEL0 &= ~BIT2;
    P2SEL1 &= ~BIT2;
}

void SPI_Init(void) {
    // Selecting the P1.1 and P1.3 and disabling the interrupt
    P1SEL1 = BIT1 + BIT2 + BIT3;

    UCB0CTL1 |= UCSWRST;                            // Holding USCI in reset state
    UCB0CTL0 |= UCSYNC;                             // Setting to SPI mode
    UCB0CTL0 &= ~UC7BIT >> 8;                       // Setting to 8-bit data
    UCB0CTL0 |= UCMODE_0 >> 8;                      // 3-pin SPI
    UCB0CTL0 |= UCMST >> 8;                         // Master Mode selected
    UCB0CTL0 |= UCMSB >> 8;                         // AIS2IH uses MSB
    UCB0CTL0 &= ~ UCCKPL >> 8;                      // Inactive state is low
    UCB0CTL1 |= UCSSEL__SMCLK;                    
    UCB0BR0 = 0x02;                                 
    UCB0CTL1 &= ~UCSWRST;                           // Finishing Setup
    PM5CTL0 &= ~LOCKLPM5;                     
}


int32_t msp430_spi_TX(uint8_t data) {
    while (!(UCTXIFG)); // Waiting for sensor getting ready to transfer
    UCB0TXBUF = data;
    while ((UCB0STAT & UCBUSY));
    return 0;
}

int32_t msp430_spi_RX(uint8_t *data) {
    while (!(UCRXIFG)); // Waiting for sensor getting ready to receive
    *data = UCB0RXBUF;
    while ((UCB0STAT & UCBUSY));
    return 0;
}

int32_t platform_write(void *handle, uint8_t Reg, const uint8_t *Bufp, uint16_t len) {
    int32_t ret;
    CSCTL5 |= SMCLKOFF;
    P2OUT &= ~BIT2;
    while(P2OUT&BIT2 != BIT2);
    uint8_t ad_w = Reg & ~BIT7;
    ret = msp430_spi_TX(ad_w);
    uint16_t i=0;
    for(;i < len; i++){
        if(ret == 0){
            ret = msp430_spi_TX(Bufp[i]);
        }
    }
    P2OUT |= BIT2;
    CSCTL5 &= ~SMCLKOFF;
    return ret;
}

int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len) {
    int32_t ret;
    CSCTL5 |= SMCLKOFF;
    P2OUT &= ~BIT2;
    while(P2OUT&BIT2 != BIT2);
    uint8_t ad_r = Reg | BIT7;
    ret = msp430_spi_TX(ad_r);
    uint16_t i=0;
    for(;i < len; i++){
        if(ret == 0){
            ret = msp430_spi_RX(Bufp + i);
        }
    }
    P2OUT |= BIT2;
    return ret;
}

void Ais2ih_device(void) {
    uint8_t whoamI;
    stmdev_ctx_t dev_ctx;
    dev_ctx.write_reg = platform_write;
    dev_ctx.read_reg = platform_read;
    ais2ih_device_id_get(&dev_ctx, &whoamI);
    if (whoamI != AIS2IH_ID)
      while (1) {
        /* manage here device not found */
      }
}

 

1 REPLY 1
Ni
Associate

Quick note:I turn on the clock after platform_read as well. Just missed to add it