RA0 SPI without interrupt

Hello everyone

I'm using a Renesas RA0 microcontroller. I would like to know if there is some example code showing how to use the SAU peripheral for SPI WITHOUT using interrupt. I use the SPI for both receiving and transmitting data in Master Mode.

Thanks in advance,

Br

Davide Petralia

Parents Reply Children
  • Yes, cause RA0 and RA2 are using different peripheral to implement SPI protocol, so on RA0 you have to enable the IRQ of SAU to implement the SPI function.

  • So there is no way to poll the SPI end-of-transimission neither start the SPI tx within a block that contains a __disable_irq( ); ?

  • Good morning, at the end we were able to implement the SPI WITHOUT  using interrupt. Here below a code example. Besides I noted that the code works if I the register R_SAU0 and not if I use g_spi0_ctrl.p_reg->SDR. After I gave a look at the code it seems that
    p_reg is never initialized

    _STATIC_INLINE_ uint16_t SPISendReceiveNOCallback( void )
    {
      DisableInterrupt( );
    
      uint32_t spiTimeout   = UINT16_MAX;
      uint16_t receivedData = 0;
    
      /* Assert Slave select pin to start data transfer */
      CSAssert( );
    
      /* Write/Read data to/from ASIC */
      for ( uint8_t i = 0; i < SPI_NUM_BYTES; ++i )
      {
        /* Set the data and reset the timeout */
        spiTimeout                              = UINT16_MAX;
        R_SAU0->SDR[g_spi0_ctrl.p_cfg->channel] = spiTx[i];
    
        while ( R_SAU0->SSR_b[g_spi0_ctrl.p_cfg->channel].TSF != 0 )
        {
          --spiTimeout;
          if ( 0 == spiTimeout )
          {
            assert( false );
          }
        }
    
        /* Check for overflow error */
        uint16_t err_type = R_SAU0->SSR[g_spi0_ctrl.p_cfg->channel] & R_SAU0_SSR_OVF_Msk;
        if ( err_type != 0 )
        {
          R_SAU0->SIR[g_spi0_ctrl.p_cfg->channel] = err_type;
        }
        else
        {
          /* Read data */
          spiRx[i] = ( uint8_t )( R_SAU0->SDR[g_spi0_ctrl.p_cfg->channel] & UINT8_MAX );
        }
      }
    
      /* De-assert Slave select pin to stop data transfer */
      CSDeassert( );
    
      EnableInterrupt( );
      receivedData = ( uint16_t )( ( spiRx[0] << SHIFT_HIGH_BYTE ) | ( spiRx[1] ) );
    
      return receivedData;
    }