TX/RX 16 bits data SPI in MSP432 from TI

39 views Asked by At

enter image description here

enter image description here

Hello, I am trying to communicate with the AS5048A encoder that requires a 16-bit SPI communication, but I am trying to establish communication with a MSP432 microcontroller and its SPI TX/RX buffers are 8 bits (because the MSB byte is reserved) and I can't establish the communication. I would like to know if someone can see what the error is or if it is the right way to do it.

uint8_t SPI_Transfer(uint8_t byte) {

    // Wait for transmit buffer to be empty
    while (!(EUSCI_A3->IFG & EUSCI_A_IFG_TXIFG));

    // Write data to transmit buffer
    EUSCI_A3->TXBUF = byte;

    // Wait for receive buffer to be full
    while (!(EUSCI_A3->IFG & EUSCI_A_IFG_RXIFG));

    // Read data from receive buffer
    return EUSCI_A3->RXBUF;
}

uint16_t AS5048A_ReadAngle(void) {

    uint16_t angulo = 0;

    uint8_t comando[2] = {0xFF, 0xFF};

    // Select AS5048A
    P9->OUT &= ~BIT4;


    for(i = 0; i < 2; i++){

        angle[i] = SPI_Transfer(comando[i]);  // Send read command

    }

    // Send dummy byte to receive angle
    // angulo = SPI_Transfer(0x0000);

    // Deselect AS5048A
    P9->OUT |= BIT4;

    angulo = ((angle[0] << 8) | (angle[1])); //conversion to uint16t
    angulo =  angulo & 0x3FFF; // to eliminate two first bits that don't represent data (err and parity)

    return angulo;
}

Thank you very much in advance.

0

There are 0 answers