Jump to content
43oh

Master SPI TX, when can I send the next byte


Recommended Posts

I'm writing an SPI driver for MSP430F5528 chip.

I'm using the driverlib from TI for working with the SPI.

 

I need to send 3 bytes.

When I'm sending the 3 bytes one after the other, only the third byte is actually sent, like the first two were overriden.

I tried waiting until the SPI bus won't be busy. but than I get gaps between the bytes, the CLK stops between them and the perihpheral doesn't work.

I tried also turning the SPI's TX interrupt, and wait until the interrupt occurr, but aperently, the bytes are overriden like before.

Here's some code for reference:

  GPIO_setAsOutputPin( GPIO_PORT_P6, GPIO_PIN6 );

  GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN6 ); // Set CS UP
 
  GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P4,
        GPIO_PIN2
        );
 
  GPIO_setAsPeripheralModuleFunctionOutputPin(
      GPIO_PORT_P4,
      GPIO_PIN1 + GPIO_PIN3
      );
  retval = USCI_B_SPI_masterInit(USCI_B1_BASE,
                        USCI_B_SPI_CLOCKSOURCE_ACLK,
                        UCS_getACLK(__MSP430_BASEADDRESS_UCS__),
                        SPICLK,
                        USCI_B_SPI_MSB_FIRST,
                        USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, /* CPHA=0 */
                        USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW /* CPOL=0 */
                        );
 
   //Enable SPI module
  USCI_B_SPI_enable(USCI_B1_BASE);

/* Send few bytes with interrupt waiting.

    USCI_B_SPI_clearInterruptFlag ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT );
    USCI_B_SPI_enableInterrupt ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT );
    GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_PIN6 ); // Set CS DOWN

      USCI_B_SPI_transmitData(USCI_B1_BASE, 0x1);
      while ( !USCI_B_SPI_getInterruptStatus ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT ) ) ;
      USCI_B_SPI_transmitData(USCI_B1_BASE, 0x2);
      while ( !USCI_B_SPI_getInterruptStatus ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT ) ) ;
      USCI_B_SPI_transmitData(USCI_B1_BASE, 0x3);
      while ( !USCI_B_SPI_getInterruptStatus ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT ) ) ;

    GPIO_setOutputHighOnPin(GPIO_PORT_P6, GPIO_PIN6 ); // Set CS UP
    USCI_B_SPI_disableInterrupt ( USCI_B0_BASE, USCI_B_SPI_TRANSMIT_INTERRUPT );

 

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...