how to 32bits frame at once from efm32 controller

Thread Starter

yef smith

Joined Aug 2, 2020
293
Hello,I am trying to send 32bits at once from my USART in my efm32 controller.
I improvised the following way where i define usart frame register first 4 bitfield as 13(to have 16 bit frame as shown in manual bellow)using:

Code:
USART0->FRAME=USART0->FRAME&(0xFFFFFFF<<4) //leaving all bits except the first 4
USART0->FRAME=USART0->FRAME|(0b1010)
Using the TXDOUBLE register i put the first 16 variable in 0-15 place and second 16bit variable at 16-31 places using(as shown in the manual bellow)
Code:
USART0->TXDOUBLE=(USART0->TXDOUBLE)&(0xFFFF<<16)//zeros at b15-b0
USART0->TXDOUBLE=USART0->TXDOUBLE|TxBuffer[0]; //setting b15-b0  
USART0->TXDOUBLE=(USART0->TXDOUBLE)&(0xFFFF)//zeros at b31-b16
USART0->TXDOUBLE=USART0->TXDOUBLE|(TxBuffer[1]<<16); //setting b31-b16
Is this a valid method?
Did i implemented correctly the bitfield value setting?
The full code is shown bellow.
Thanks.
Code:
#define TX_BUFFER_SIZE   2
    #define RX_BUFFER_SIZE   TX_BUFFER_SIZE
   
    //W/R=0 write and update channeL0  all1 data    dont cate
    uint16_t TxBuffer[TX_BUFFER_SIZE] = {0b0000001100001111,0b1111111111110000};
   

    uint32_t TxBufferIndex = 0;
   
    uint8_t RxBuffer[RX_BUFFER_SIZE] = {0};
    uint32_t RxBufferIndex = 0;
   
    volatile uint32_t msTicks; /* counts 1ms timeTicks */
   
    void Delay(uint32_t dlyTicks);
   
    void SysTick_Handler(void)
    {
      msTicks++;       /* increment counter necessary in Delay()*/
    }
   
    void Delay(uint32_t dlyTicks)
    {
      uint32_t curTicks;
   
      curTicks = msTicks;
      while ((msTicks - curTicks) < dlyTicks) ;
    }
   
    int main(void)
    {
      // Initialize chip
      CHIP_Init();
      if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
            while (1) ;
      }
   
      CMU_ClockEnable(cmuClock_GPIO, true);
      CMU_ClockEnable(cmuClock_USART0, true);
      GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0); // US1_CLK is push pull
        GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 1); // US1_CS is push pull
        GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0); // US1_TX (MOSI) is push pull
        GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 1);    // US1_RX (MISO) is input
        GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);    // LDAC
        GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 1);    // CLR
      ///////////////////////////////////////////////////////
      // Start with default config, then modify as necessary
       USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;
       config.master       = true;            // master mode
       config.baudrate     = 1000000;         // CLK freq is 1 MHz
       config.autoCsEnable = false;            // CS pin controlled by hardware, not firmware
       config.clockMode    = usartClockMode0; // clock idle low, sample on rising/first edge
       config.msbf         = true;            // send MSB first
   
       USART_InitSync(USART0, &config);
       USART0->ROUTE = USART_ROUTE_CLKPEN | USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
       ///////////////////////////////////////////
       USART_Enable(USART0, usartEnable);
        TxBufferIndex = 0;
        USART0->IEN = USART_IEN_TXC; //enable TXC interrupt flag
        USART0->FRAME=USART0->FRAME&(0xFFFFFFF<<4) //leaving all bits except the first 4
        USART0->FRAME=USART0->FRAME|(0b1010)
   

      while(1)
      {
          Delay(1);
            GPIO_PinOutClear(gpioPortA,2);
            USART0->TXDOUBLE=(USART0->TXDOUBLE)&(0xFFFF<<16)//zeros at b15-b0
            USART0->TXDOUBLE=USART0->TXDOUBLE|TxBuffer[0]; //setting b15-b0  
            USART0->TXDOUBLE=(USART0->TXDOUBLE)&(0xFFFF)//zeros at b31-b16
            USART0->TXDOUBLE=USART0->TXDOUBLE|(TxBuffer[1]<<16); //setting b31-b16
              while( !(USART0->STATUS & USART_STATUS_TXC) );  //wait TILL TXC goes high
              GPIO_PinOutSet(gpioPortA,2);
          Delay(2000);
   

      }

}[/CODE]
 

Attachments

Last edited:
Top