SPI implementation stuck on “while(!spi_is_tx_empty(WINC1500_SPI));”

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm currently implementing a driver for the WINC1500 to be used with an ATMEGA32 MCU and it's getting stuck on this line of "while(!spi_is_tx_empty(WINC1500_SPI));". The code builds and runs but it won't clear what's inside in this function to proceed through my code and boot up the Wifi Module. I've been stuck on this problem for days searching all over the place and can't figure it what's causing the problem. 

static inline bool spi_is_tx_empty(volatile avr32_spi_t *spi)
{
    // 1 = All Transmissions complete
    // 0 = Transmissions not complete 
    return (spi->sr & AVR32_SPI_SR_TXEMPTY_MASK) != 0;
}

 

Here is my implementation of the SPI Tx/Rx function

void m2mStub_SpiTxRx(uint8_t *p_txBuf,
uint16_t txLen,
uint8_t *p_rxBuf,
uint16_t rxLen)
{
    uint16_t byteCount;
    uint16_t i;

    uint16_t data;

    // Calculate the number of clock cycles necessary, this implies a full-duplex SPI.
    byteCount = (txLen >= rxLen) ? txLen : rxLen;

    // Read / Transmit.
    for (i = 0; i < byteCount; ++i)
    {
        // Wait for transmitter to be ready.
        while(!spi_is_tx_ready(WINC1500_SPI));

        // Transmit.
        if (txLen > 0)
        {
            // Send data from the transmit buffer
            spi_put(WINC1500_SPI, *p_txBuf++);
            --txLen;
        }
        else
        {
            // No more Tx data to send, just send something to keep clock active.
            // Here we clock out a don't care byte 
            spi_put(WINC1500_SPI, 0x00U);

            // Not reading it back, not being cleared 16/1/2020
        }

        // Reference http://asf.atmel.com/docs/latest/avr32.components.memory.sdmmc.spi.example.evk1101/html/avr32_drivers_spi_quick_start.html
        // Wait for transfer to finish, stuck on here
        // Need to clear the buffer for it to be able to continue 
        while(!spi_is_tx_empty(WINC1500_SPI));

        // Wait for transmitter to be ready again
        while(!spi_is_tx_ready(WINC1500_SPI));

        // Send dummy data to slave, so we can read something from it.
        spi_put(WINC1500_SPI, 0x00U);    // Change dummy data from 00U to 0xFF idea

        // Wait for a complete transmission
        while(!spi_is_tx_empty(WINC1500_SPI));

        // Read or throw away data from the slave as required.
        if (rxLen > 0)
        {
            *p_rxBuf++ = spi_get(WINC1500_SPI);
            --rxLen;
        }
        else
        {
            spi_get(WINC1500_SPI);
        }
    }
Last Edited: Sat. Jan 18, 2020 - 02:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An ATMEGA32 is an 8-bit processor but the code shown is for an AVR32 32-bit processor.
What processor are you actually using ?
If it is for an AVR32 then what is the definition of WINC1500_SPI ? and is that SPI module initialised ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using an AT32UC1256C Microcontroller. The SPI Module is getting called in my code.

Here's my debug output log from Atmel Studio below here of what's happening when I'm trying to boot up the WINC1500 Module communicating with the MCU.  

 

Disable SPI
Init SPI module as master
Configure SPI and Clock settings
spi_enable(WINC1500_SPI)
InitStateMachine()
INIT_START_STATE
InitStateMachine()
INIT_WAIT_FOR_CHIP_RESET_STATE
m2mStub_PinSet_CE
m2mStub_PinSet_RESET
m2mStub_GetOneMsTimer();
SetChipHardwareResetState (CHIP_HARDWARE_RESET_FIRST_DELAY_1MS)
InitStateMachine()
INIT_WAIT_FOR_CHIP_RESET_STATE
if(m2m_get_elapsed_time(startTime) >= 2)
m2mStub_PinSet_CE(M2M_WIFI_PIN_HIGH)
startTime = m2mStub_GetOneMsTimer();
SetChipHardwareResetState(CHIP_HARDWARE_RESET_SECOND_DELAY_5_MS);
InitStateMachine()
INIT_WAIT_FOR_CHIP_RESET_STATE
m2m_get_elapsed_time(startTime) >= 6
m2mStub_PinSet_RESET(M2M_WIFI_PIN_HIGH)
startTime = m2mStub_GetOneMsTimer();
SetChipHardwareResetState(CHIP_HARDWARE_RESET_FINAL_DELAY);
InitStateMachine()
INIT_WAIT_FOR_CHIP_RESET_STATE
m2m_get_elapsed_time(startTime) >= 10
SetChipHardwareResetState(CHIP_HARDWARE_RESET_COMPLETE)
retVal =  true // State machine has completed successfully
g_scanInProgress = false
nm_spi_init();
reg = spi_read_reg(NMI_SPI_PROTOCOL_CONFIG)
Wait for a complete transmission
Wait for transmitter to be ready
SPI_PUT(WINC1500_SPI, *p_txBuf++);
--txLen;
Wait for transfer to finish, stuck on here
Wait for transfer to finish, stuck on here

 

Last Edited: Sat. Jan 18, 2020 - 08:50 AM