Перейти к содержанию
    

manual chip select for SPI handle

Hello, I have situation with my EFM32LG where i need to define a manual operating chipselect select and to manualy defining the USART location of my SPIDRV handle.

Regarding the location 0 definition , i need LOC0 because my controller Is connected to DAC USING port E.

So in the INIT of the handle i looked where could be the USART define inside the handle I saw USART type in a variable called PORT( i am not sure if its the one)

and i defined the location0 manually using the route register table of the reference manual shown bellow.

initData.port->ROUTE &= ~((1 << 8)|(1 << 9)|(1 << 10));

Regarding the second part of the manual CHIP SELECT  ,i defined a GPIO PIN manually turned it to zero transfered of the data and after that raised it back.

as shown in the full code bellow ,I am not sure if its the way because  the while loops performs all the operations in one clock cycle.
Is my intuition correct?

Thanks.

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.port->ROUTE &= ~((1 << 8)|(1 << 9)|(1 << 10));

SPIDRV_Init(handle, &initData);
GPIO_PinOutClear(LED_PORT_A,2); //chip select low starts transmition
SPIDRV_MTransmitB(handle, B31_B24, 8);
SPIDRV_MTransmitB(handle, B23_B16, 8);
SPIDRV_MTransmitB(handle, B15_B8, 8);
SPIDRV_MTransmitB(handle, B7_B0, 8);
GPIO_PinOutSet(LED_PORT_A,2); // chip select high,end transmition

SPIDRV_MReceiveB(handle,buffer,32) //reading the data back from DAC



 

image.thumb.png.829c9e01c8d9183b76bfd300442998d1.png

image.thumb.png.69a91f01afb6991d389adb5bf8c163c2.png

 

image.thumb.png.77d3adfdeb554e0be702926decc9ccf4.png

 

 

Изменено пользователем sergei94

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Is my intuition correct?


Коллега, у вас же на рабочем месте labkit с отладчиком, в симплисити-студио все "потроха" как на ладони, можно даже руками в регистрах требуемые биты устанавливать\сбрасывать.
Не, если вы "пеший по-конному", то пардон...

SPIDRV_MTransmitB(handle, B31_B24, 8);


То, что отправляется из B31_B24 - понятно, куда будет помещён принятый (SPI синхронно передаёт и принимает) байт? SPIDRV_MTransmitB - ждёт окончания передачи?

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

"SPIDRV_MTransmitB - ждёт окончания передачи?"
The data goes into DAC shift register,In theory he is waiting when CS goes HIGH.

 

Изменено пользователем sergei94

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Хорошая у вас теория - "годная" (шутка)
Я имел ввиду, что SPIDRV_MTransmitB не пишет в несвободный DATA-регистр.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Я имел ввиду, что SPIDRV_MTransmitB не пишет в несвободный DATA-регистр.

 

Hello,From the API link bellow it says that this command will "BLOCK" something till it finishes the transfer.

I just want to send four times the 8bits(one after the other) 32bit , in this command to my DAC to configure a value on it.
You say that when we write the 4 commands as shown bellow then they will not run one after the other

but they will run in parralel and block each other?
 

did i choose the correct command to transmit my databits from the controller master and DAC SLAVE?

Thanks.

SPIDRV_MTransmitB(handle, B31_B24, 8);
SPIDRV_MTransmitB(handle, B23_B16, 8);
SPIDRV_MTransmitB(handle, B15_B8, 8);
SPIDRV_MTransmitB(handle, B7_B0, 8);

https://docs.silabs.com/mcu/latest/efm32lg/group-SPIDRV#gaf53f10ccb89d8ae2c5c397db7cb87a9e

 

 

Изменено пользователем sergei94

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

this command will "BLOCK" something till it finishes the transfer


Всё понятно - блокирующий обмен, будет 4 записи друг за другом.

Вы всё это уже 10 раз могли проверить.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Hello i have written the following code for efm32LG and tried to track the CLK SIGNAL with debugging mode  ,when i do the transmit command for SPI. i have used LOCATION0 as shown in the datasheet in the the first post, 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

 

Изменено пользователем sergei94

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...