Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Wi-Fi Combo Forum Discussions

LeonH
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

I added spi master code in Wiced scan example code with CYW943012EVB(STM32L4A6+CYW43438) ,

and connect it to CY8CPROTO-062-4343W to control led via spi interface.

It seems spi master not work in CYW943012EVB, does Cypress have any spi master example code? 

 

Code:

SPI_HandleTypeDef SPI1_Handler;

void SPI1_Init(void)
{
  SPI1_Handler.Instance=SPI1;
  SPI1_Handler.Init.Mode=SPI_MODE_MASTER;
  SPI1_Handler.Init.Direction=SPI_DIRECTION_2LINES;
  SPI1_Handler.Init.DataSize=SPI_DATASIZE_8BIT;
  SPI1_Handler.Init.CLKPolarity=SPI_POLARITY_HIGH;
  SPI1_Handler.Init.CLKPhase=SPI_PHASE_2EDGE;
  SPI1_Handler.Init.NSS=SPI_NSS_SOFT;
  SPI1_Handler.Init.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16;
  SPI1_Handler.Init.FirstBit=SPI_FIRSTBIT_MSB;
  SPI1_Handler.Init.TIMode=SPI_TIMODE_DISABLE;
  SPI1_Handler.Init.CRCCalculation=SPI_CRCCALCULATION_DISABLE;
  HAL_SPI_Init(&SPI1_Handler);
}


void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
  GPIO_InitTypeDef GPIO_Initure;
  if(hspi->Instance==SPI1)
  {
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_SPI1_CLK_ENABLE();

   GPIO_Initure.Pin=GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;
   GPIO_Initure.Mode=GPIO_MODE_AF_PP;
   GPIO_Initure.Pull=GPIO_PULLUP;
   GPIO_Initure.Speed=GPIO_SPEED_HIGH;
   GPIO_Initure.Alternate=GPIO_AF5_SPI1;
   HAL_GPIO_Init(GPIOA,&GPIO_Initure);
 }
}

void application_start( )
{
  uint8_t txData=0x00;

  wiced_init( );
  SPI1_Init();
  HAL_SPI_Init(&SPI1_Handler);

  while(1)
  {
    wiced_time_t scan_start_time;
    wiced_time_t scan_end_time;
    app_scan_data_t scan_data;

    /* Initialize the semaphore that will tell us when the scan is complete */ 
    wiced_rtos_init_semaphore(&scan_data.semaphore);
    scan_data.result_count = 0;
    WPRINT_APP_INFO( ( "Waiting for scan results...\n" ) );
    WPRINT_APP_INFO( (" # Type BSSID RSSI Rate Chan Security SSID CCode Flag\n" ) );
    WPRINT_APP_INFO( ("------------------------------------------------------------------------------------------------------------------\n" ) );
    /* Start the scan */
    wiced_time_get_time(&scan_start_time);
    wiced_wifi_scan_networks(scan_result_handler, &scan_data );

    /* Wait until scan is complete */
    wiced_rtos_get_semaphore(&scan_data.semaphore, WICED_WAIT_FOREVER);
    wiced_time_get_time(&scan_end_time);

    WPRINT_APP_INFO( ("\nScan complete in %lu milliseconds\n", (unsigned long )(scan_end_time - scan_start_time) ) );

    /* Clean up */
    wiced_rtos_deinit_semaphore(&scan_data.semaphore);
    /* Issuing next scan after some delay (optional) */
    txData = 0;
    WPRINT_APP_INFO( ( "txData=%d\n", txData ) );
    HAL_SPI_Transmit(&SPI1_Handler, &txData, 1, 1000);

    wiced_rtos_delay_milliseconds(DELAY_BETWEEN_SCANS);

    txData = 1;
    WPRINT_APP_INFO( ( "txData=%d\n", txData ) );
    HAL_SPI_Transmit(&SPI1_Handler, &txData, 1, 1000);
}
}

0 Likes
3 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
First comment on KBA 10 questions asked 5 questions asked

 Hello:

   CYW943012EVB(STM32L4A6+CYW43012), is this right?  Actually,  You are using SPI of STM32L4A6 to connect with the SPI of CY8CPROTO-062-4343W , Psoc6, is this right ? 

   So Psoc6 is the slave side ,  How did you confirm SPI master not working in STM side ?

0 Likes
LeonH
Level 2
Level 2
25 sign-ins 10 replies posted 10 sign-ins

Yes, I'm using CYW943012EVB_04.

SPI master : PSoC6(CY8CPROTO-062-4343W)

SPI slave: STM32L4A6(CYW943012EVB_04)

Because I have no scope at my hand, I use digital multimeter measure SPI clock.

While spi enabling , I can see voltage jump from 0~1.7V on PSoC6, but STM32L4A6  spi clock voltage always = 0V.

0 Likes
Zhengbao_Zhang
Moderator
Moderator
Moderator
First comment on KBA 10 questions asked 5 questions asked

Hello:

  I can't find accurate memo for STM32L4XX SPI usage, but you can have a check on below address:

 WICED/platform/MCU/STM32L4xx/peripherals/libraries/Drivers/STM32L4xx_HAL_Driver/src/stm32l4xx_II_spi.c   , you can get api from this c file,  and try to find the usage from instructions and the code. 

0 Likes