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 weeks now with no progress and don't know how to clear it.

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);
    }
}

Debug output log

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
Sahil Bora
  • 173
  • 1
  • 12

1 Answers1

0

The ATmega32 is an 8-bit AVR but you seem to be using code for the AVR32, a family of 32-bit AVRs. You're probably just using the totally wrong code and you should consult the datasheet of the ATmega32, and search for SPI for the AVR ATmega family.

David Grayson
  • 84,103
  • 24
  • 152
  • 189