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.

CCS/MSP430F5529: MSP430F5529 SPI COMMUNICATION

Part Number: MSP430F5529


Tool/software: Code Composer Studio

Dear All,

This is vikash Chandra Raman, I am doing a project on MSP430F5529. I am interfacing ACS71020 ic with SPI Communications. I have to send 32 bit registers through Spi And also i have to recieve 32 bit data from ACS71020 on controller RXBUFF.

i have send 32 bit registers, through send functions, kindly check my send function.

sync_low;

send(0x2325,2),send(0x5626,2)

sync_high;

void send( int data,int i)
{
int l;
__disable_interrupt();
l=data;
l=l>>8;
while(i){
while(!( UCB1IFG & UCTXIFG));
UCB1TXBUF = l;
l=data;
i--;
}
while(UCB1STAT & UCBUSY);
__enable_interrupt();


}

It successfully send, But when i recieve the data it only recieve 8 bit , it is showing on RXBUFF.

So , i requested to say that if i have to recieve 32 bit data on rxbuff, what should i do.

kindly tell me the solution or give some ideas.

waiting for your positive response

Vikash chandra Raman

Comcon industries

New-Delhi

  • Hello Vikash,

    Check the ACS71020 datasheet.  It appears you will read the data from the slave on the MISO pin.  I suspect you need 32 clocks to read the 32bit data result.

  • Respected sir,

    when we send 32 bit data on MISO, , It takes 32 clock to send it right. But after sending when we check the data on SIMO it appear only 8 bit data on SIMO Pins, that is 0xFF. What does it means?

    beacause acs71020 IC gives the output of 32 bits.

    so my questions is that when i recieve the data bit wise bit through interputs.

    i am writting a code on msp430f5529, i request you kindly see my send function and recieve function, and tell me where i am wrong?

    void send( int data,int i)
    {
    int l;
    __disable_interrupt();
    l=data;
    l=l>>8;
    while(i){
    while(!( UCB1IFG & UCTXIFG));
    UCB1TXBUF = l;
    l=data;
    i--;
    }
    while(UCB1STAT & UCBUSY);
    // __enable_interrupt();
    __bis_SR_register(GIE);


    }

    #pragma vector=USCI_B1_VECTOR
    __interrupt void USCI_B1_ISR(void)
    {
    switch(__even_in_range(UCB1IV,4))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    for(i=0;i<32;i++)
    {
    if(i==32){
    Flag=1;
    UCB1IFG &=~ UCRXIFG;
    break;
    }
    while (!(UCB1IFG & UCRXIFG));
    *value = UCB1RXBUF;
    value++;
    }
    __bis_SR_register(GIE);
    break;

    case 4:break; // Vector 4 - TXIFG
    default: break;
    }
    }

    Here my data is :

    /*Custmer access code (0x4F70656E) WITH ADDRESS 0x2F*/
    P3OUT&=~BIT7;
    send(0x2F,1);
    send(0x4F70,2);
    send(0x656E,2);
    P3OUT|=BIT7;

    while(1)
    {
    __delay_cycles(1234);
    P3OUT&=~BIT7;
    send(0x20,1);
    __delay_cycles(4321);
    P3OUT|=BIT7;

    }

    here i am using 4 -pin SPI

    void init_UCB1(void)
    {
    P4SEL|=BIT1+BIT2+BIT3;
    UCB1CTL1 |= UCSWRST;
    UCB1CTL0 = UCCKPH + UCMSB + UCMST + UCMODE_1 + UCSYNC; //UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;
    UCB1CTL1 = UCSSEL_2;
    //UCB0BR0 = 255;
    UCB1CTL1 &=~UCSWRST;
    }

    Please check my code, where i am wrong, because i am not recieving the data 32 bit on simo pins.

    waiting for your Positive response

    Vikash Chandra Raman

    Comcon Industries

    New -Delhi

  • Part Number: MSP430F5529

    Tool/software: Code Composer Studio

    Dear sir,

    This is Vikash chandra Raman from Comcon-Industries. I am doing a project related to measure the current as well as voltages. For measuring the current and voltages i am using a MSP430F5529 controller interfacing with spi communications( 4 wire communications).

    I have to send 32 bit data and also recieve the 32 bit data on SOMI(RX) pin.

    I have send the data of 32 bit along with address , but when i recieve the data it only recieve 8 bit data on somi pin. I request you kindly check my code or give me some idea how to recieve 32 bit data on somi pins.

    For setup SPI communication i am using the following registers as well as whole codes

    #include <msp430.h>

    short int arry[32]={0};
    short int *value=arry;
    unsigned int i=0,size=0,Flag=0;

    void PinSetup()
    {
    /*CS1*/
    P4DIR|=BIT0;
    /*CS2*/
    P3DIR|=BIT7;
    P3OUT|=BIT7;
    /*CS3*/
    P3DIR|=BIT6;
    P3OUT|=BIT6;

    }
    void init_UCB1(void)
    {
    P4SEL|=BIT1+BIT2+BIT3;
    UCB1CTL1 |= UCSWRST;
    UCB1CTL0 = UCCKPH + UCCKPL + UCMST + UCMODE_1 + UCSYNC; //UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;
    UCB1CTL1 = UCSSEL_2;
    //UCB0BR0 = 255;
    UCB1CTL1 &=~UCSWRST;
    UCB1IE |= UCRXIE;
    }
    void send( int data,int i)
    {
    int l;
    __disable_interrupt();
    l=data;
    l=l>>8;
    while(i){
    while(!( UCB1IFG & UCTXIFG));
    UCB1TXBUF = l;
    l=data;
    i--;
    }
    while(UCB1STAT & UCBUSY);
    __enable_interrupt();


    }
    void send_8bit( int data,int i)
    {
    __disable_interrupt();
    while(i){
    while(!( UCB1IFG & UCTXIFG));
    UCB1TXBUF = data;
    i--;
    }
    while(UCB1STAT & UCBUSY);
    __enable_interrupt();
    }


    void main(void)
    {

    WDTCTL = WDTPW + WDTHOLD;
    PinSetup();
    init_UCB1();

    /*Custmer access code (0x4F70656E) WITH ADDRESS 0x2F*/
    P4OUT&=~BIT0;
    /*READ_1 && WRITE_0*/
    send_8bit(0x2F,1);

    send(0x6E65,2);
    send(0x704F,2);
    // P4OUT|=BIT0;

    while(1){
    // __delay_cycles(1234);
    P4OUT&=~BIT0;
    send_8bit(0xA0,1);//? READ OR WRITE??
    send(0x0000,2);
    send(0x0000,2);
    // __delay_cycles(4321);
    // P4OUT|=BIT0;
    value=arry;

    }

    }

    #pragma vector=USCI_B1_VECTOR
    __interrupt void USCI_B1_ISR(void)
    {
    switch(__even_in_range(UCB1IV,4))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    // for(i=0;i<32;i++)
    // {
    // if(i==32){
    // Flag=1;
    // UCB1IFG &=~ UCRXIFG;
    // break;}

    while (!(UCB1IFG & UCTXIFG));
    *value = UCB1RXBUF;
    value++;
    // }
    // __bis_SR_register(GIE);
    break;

    case 4:break; // Vector 4 - TXIFG
    default: break;
    }
    }

    Kindly suggest me a answer so that i am able to read 32 bit data on SOMI pins.

    waiting for your positive response

    Vikash chandra raman

    Comcon industries

    New -Delhi

  • Hi Vikash,

    Please see the attached file.  I have this working on 5529 launchpad.  I had to use UCB0 so I can access pins and confirm data. This should give you a basic idea.  Let me know if this is not clear

    #include <msp430.h> 
    #include <stdint.h>
    
    uint8_t buffer[4];
    uint8_t* rxPtr;
    uint8_t bytesToRead = 0;
    
    
    #define LOBYTE(x)           (x & 0x00FF)
    #define HIBYTE(x)           ((x & 0xFF00) >> 8)
    
    
    void send8bit(uint8_t data)
    {
        while(!( UCB0IFG & UCTXIFG));
            UCB0TXBUF = data;
    }
    
    void send16bit(uint16_t data)
    {
        while(!( UCB0IFG & UCTXIFG));
                UCB0TXBUF = LOBYTE(data);
    
        _no_operation();
    
        while(!( UCB0IFG & UCTXIFG));
                UCB0TXBUF = HIBYTE(data);
    }
    
    void read(uint8_t* pBuffer, uint8_t length)
    {
    
        bytesToRead = length;
        UCB0IE |= UCTXIE;
    
    }
    
    void main(void)
    {
    
        WDTCTL = WDTPW + WDTHOLD;
        P3DIR |= BIT0 | BIT3;
        P3SEL|=BIT0+BIT1+BIT2;
    
        UCB0CTL1 |= UCSWRST;
        UCB0CTL0 = UCCKPH + UCCKPL + UCMST + UCMODE_0 + UCSYNC;
        UCB0CTL1 = UCSSEL_2;
        UCB0CTL1 &=~UCSWRST;
        UCB0IE |= UCRXIE;
    
        __enable_interrupt();  // Enable interrupts globally
    
    
        send8bit(0x2F);  // example how to send a byte
    
        send16bit(0x6E65);  // example how to send a word (2-byte)
    
        read(buffer, 4);       // clocks 32 bits (4-bytes) from the slave device
    
        // go look in buffer for data from slave
    
    
        while(1); //sit here and do nothing
    
    
    }
    
    
    #pragma vector=USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
        switch(__even_in_range(UCB0IV,4))
        {
            case 0:break; // Vector 0 - no interrupt
            case 2: // Vector 2 - RXIFG
                *rxPtr++ = UCB0RXBUF;
                break;
    
            case 4:
                UCB0TXBUF = 0x00; // dummy bytes
                if(--bytesToRead == 0)
                    UCB0IE &= ~UCTXIE;
                break; // Vector 4 - TXIFG
            default: break;
        }
    }
    

  • Dear sir,

    Thanks for reply me , this code is helpful for me and its working.

    Thanks& Regards

    vikash

**Attention** This is a public forum