Catching CLOCK signal for SPI spidrv communication

Status
Not open for further replies.

yefj

Advanced Member level 4
Joined
Sep 12, 2019
Messages
1,211
Helped
1
Reputation
2
Reaction score
3
Trophy points
38
Activity points
7,276
Hello i have written the following code for efm32LG and tried to track the CLK SIGNAL when i do the transmit command for SPI.
i have used LOCATION0 as shown in the datasheet bellow and put my scope and when i passed threw my transmit command i didnt catch any clock signal at all.
Why could it happen?
Thanks






Code:
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "spidrv.h"
#include "dmadrv.h"
#include "em_usart.h"
#include "em_chip.h"
#include <stdint.h>
#include <stdbool.h>
#include "em_emu.h"

#include "bsp.h"
#include "bsp_trace.h"
#define LED_PORT_E    gpioPortE
#define LED_PIN_E     15

#define LED_PORT_A    gpioPortA
#define LED_PIN_A     15

#define USER_LOCATION 5

#define BUFFER_SIZE 1
char buffer[BUFFER_SIZE];

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)
{

//    uint8_t *pt;
  int i,j;
   i=0;
        //start write update command
        uint8_t B7_B0=0b11110000; //first 4 are dont care,first 4 bits data
         uint8_t B15_B8=0b11111111;//data bits
         uint8_t B23_B16=0b00000111;//channel A DATA total 0000 1111 1111 1111 last bin1
         uint8_t B31_B24=0b00000011;//write to buffer and update DAC ,Write /rest dont care
         //start end update command


         uint8_t  Recieved_D[4];
         Recieved_D[0]=0b11111111;
         Recieved_D[1]=0b11111111;
         Recieved_D[2]=0b11111111;
         Recieved_D[3]=0b11111111;
        //Enable SDO register
         uint8_t C31_C24=0b00001000; //enable DSO command
         uint8_t C23_C16=0b00000000;
         uint8_t C15_C8=0b00000000;
         uint8_t C7_C0=0b00000010;// enable DSO bit

         //NO OPeration COMMAND
     //    uint8_t D31_D24=0b00001110;
     //    uint8_t D23_D16=0b00000000;
     //    uint8_t D15_D8=0b00000000;
     //    uint8_t D7_D0=0b00000000;


          //start read command 0000
                 uint8_t E7_E0=0b11110000; //first 4 are dont care,first 4 bits data
                  uint8_t E15_E8=0b11111111;//data bits
                  uint8_t E23_E16=0b00000000;//channel A rest is dont care
                  uint8_t E31_E24=0b00010000;//read
                  //start end update command

                  //NO OPeration COMMAND
                           uint8_t F31_F24=0b00001110;
                           uint8_t F23_F16=0b00000000;
                           uint8_t F15_F8=0b00000000;
                           uint8_t F7_F0=0b00000000;
  // Chip errata
  CHIP_Init();

  // Enable oscillator to GPIO and USART1 modules
  CMU_ClockEnable(cmuClock_GPIO, true);
  CMU_ClockEnable(cmuClock_USART1, true);
  CMU_ClockEnable(cmuClock_USART0, true);





//  BSP_TraceProfilerSetup();

    /* Setup SysTick Timer for 1 msec interrupts  */
    if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
      while (1) ;
    }

    /* Initialize LED driver */

  //  BSP_LedsInit();
  //  BSP_LedSet(0);
  // set pin modes for UART TX and RX pins
  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
  ///////////////////////////////////
    USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
    USART_InitAsync(USART1, &init);
    //defining location 5 so PORT C will be tx an rx for async uart
    USART1->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN|USART_ROUTE_LOCATION_LOC0;
   // GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,1);

      GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,1);

    GPIO_PinModeSet(LED_PORT_A,2,gpioModePushPull,1);
    SPIDRV_HandleData_t handleData;
      SPIDRV_Handle_t handle = &handleData;
      SPIDRV_Init_t initData =  SPIDRV_MASTER_USART0;
      initData.csControl=spidrvCsControlApplication; //manual CS
      initData.bitOrder=1; //MSB first send bit order
      initData.portLocation = USART_ROUTE_LOCATION_LOC0; //defining location 0 for sync uart
      SPIDRV_Init(handle,&initData);

      GPIO_PinOutClear(LED_PORT_A,2); //chip select low starts transmition
      SPIDRV_MTransmitB(handle, &B31_B24, 1);
      SPIDRV_MTransmitB(handle, &B23_B16, 1);
      SPIDRV_MTransmitB(handle, &B15_B8, 1);
      SPIDRV_MTransmitB(handle, &B7_B0, 1);
      GPIO_PinOutSet(LED_PORT_A,2); // chip select high,end transmition
       Delay(1000);
//////////////////
      GPIO_PinOutClear(LED_PORT_A,2); //chip select low starts transmition
      SPIDRV_MTransmitB(handle, &C31_C24, 1);
            SPIDRV_MTransmitB(handle, &C23_C16, 1);
            SPIDRV_MTransmitB(handle, &C15_C8, 1);
            SPIDRV_MTransmitB(handle, &C7_C0, 1);
        GPIO_PinOutSet(LED_PORT_A,2); // chip select high,end transmition
      Delay(1000);
      //////////////
      GPIO_PinOutClear(LED_PORT_A,2); //chip select low starts transmition
                     SPIDRV_MTransmitB(handle, &E31_E24, 1);
                    SPIDRV_MTransmitB(handle, &E23_E16, 1);
                    SPIDRV_MTransmitB(handle, &E15_E8, 1);
                    SPIDRV_MTransmitB(handle, &E7_E0, 1);
              //////////////
  GPIO_PinOutSet(LED_PORT_A,2); // chip select high,end transmition
  Delay(1000);
  GPIO_PinOutClear(LED_PORT_A,2); //chip select low starts transmition
                SPIDRV_MTransmitB(handle, &F31_F24, 1);
                                    SPIDRV_MTransmitB(handle, &F23_F16, 1);
                                    SPIDRV_MTransmitB(handle, &F15_F8, 1);
                                    SPIDRV_MTransmitB(handle, &F7_F0, 1);
      GPIO_PinOutSet(LED_PORT_A,2); // chip select high,end transmition

  // Initialize USART asynchronous mode and route pins






      GPIO_PinOutClear(LED_PORT_A,2);
       SPIDRV_MReceiveB(handle,&Recieved_D,4);
      GPIO_PinOutSet(LED_PORT_A,2);

      uint8_t * pt = (uint8_t*)(&Recieved_D);

      while (1)
     {

//E-green
//A-red

          Delay(1000);


             for (i = 0; i < 4 ; i ++ )
                 {
                // USART_Tx(USART1,*(&Recieved_D+i));
                 USART_Tx(USART1,*(pt++));
                 }
                 USART_Tx(USART1, '\n');
                 GPIO_PinOutClear(LED_PORT_E,15);
                 Delay(5000);
                 GPIO_PinOutSet(LED_PORT_E,15);
               Delay(5000);
      }//end while(1)
  }//end main
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…