Reply
Posts: 17
Registered: ‎05-15-2017

EFM8UB10F16G-B-QFN20 - SPI0_pollTransfer loop

Good morning,

 

I've been trying to use the function "SPI0_pollTransfer" of the spi0.c driver to send 48 bits of data to a ASIC.

 

While I would expect to see 48 bits of data (once) on MOSI, the program seems to loop and keeps on sending 48 bits on MISO... (see the oscillogram attached)

 

I tried dissabling the Watchdog timer as explained here: http://community.silabs.com/t5/8-bit-MCU-Knowledge-Base/MCU-constantly-resets-never-reaches-the-main...

 

Here is my code:

 

//-----------------------------------------------------------------------------

// Includes

//-----------------------------------------------------------------------------

#include <SI_EFM8UB1_Register_Enums.h>

#include <stdio.h>

#include "InitDevice.h"

#include "conf.h"

#include "uart_0.h" //UART0 Driver

#include "spi_0.h" //UART0 Driver

 

//-----------------------------------------------------------------------------

// Variables Definitions

//-----------------------------------------------------------------------------

 

uint8_t acquisition=0;

uint8_t acquisition2=0;

bool CLK6400=0;

unsigned char Data_str[4] = "0x00";

//unsigned char Data_str[8] = "00000000";

//uint8_t SPI_RxBuf[number_data_bytes];

bool SPI0_RDY;

//#define ASIC_NUMBER 0xD5 -> fait dans conf.h

//-----------------------------------------------------------------------------

// Global Constants

//-----------------------------------------------------------------------------

#define  number_data_bytes 4// The number of bytes of data to be recieved from the ASIC

#define  nombre_registres 2 // The number of register extracted per period of HTR

 

//-----------------------------------------------------------------------------

// Global Variables

//-----------------------------------------------------------------------------

 

//the memory allocations were chosen as in the examples: "EFM8UB1_UART_Lib_Buffer" and "EFM8UB1_SPI0_Lib_Master"

SI_SEGMENT_VARIABLE(UART0_TxBuf[number_data_bytes], uint8_t, SI_SEG_XDATA); //UART0 Transmit buffer. (the UART0 doesn't transmit the ASIC number and register address)

SI_SEGMENT_VARIABLE(SPI_TxBuf[number_data_bytes+2], uint8_t, EFM8PDL_SPI0_TX_SEGTYPE); //SPI0 Transmit (TX) buffer. +2 for ASIC and register address

SI_SEGMENT_VARIABLE(SPI_RxBuf[number_data_bytes+2], uint8_t, EFM8PDL_SPI0_RX_SEGTYPE); //SPI0 Receive (RX) buffer. +2 for ASIC and register address

 

//-----------------------------------------------------------------------------

// Function Prototypes

//-----------------------------------------------------------------------------

 

void SPI_Array_Read(uint8_t Register);

void SPI_Array_Write(uint8_t Register, uint8_t data1, uint8_t data2, uint8_t data3, uint8_t data4);

 

//-----------------------------------------------------------------------------

// ISR Callbacks

//-----------------------------------------------------------------------------

//These Callbacks MUST be present in the code even if unused.

void SPI0_transferCompleteCb(void) //This function is called when an interrupt-driven SPI transfer is complete. This function is called when an interrupt-driven SPI transfer is complete.

{

}

 

void UART0_receiveCompleteCb() //This function is called when all expected bytes have been received.

{

}

 

void uart0_transmitCompleteCB() //This function is called when all bytes in the buffer have been transferred.

{

 

}

 

 

//-----------------------------------------------------------------------------

// Main Routine

//-----------------------------------------------------------------------------

void main (void)

{

   uint8_t i;

   uint8_t numero_registre;

   uint8_t registres_ecriture[nombre_registres] = {0xE5, 0xE6};

 

   enter_DefaultMode_from_RESET();

 

 

   IE_EA = 1;// Enable global interrupts : overrides individual interrupts mask

 

   SPI_TxBuf[0] = ASIC_NUMBER;

   SPI_TxBuf[1] = registres_ecriture[0];

   SPI_TxBuf[2] =0xAB;

   SPI_TxBuf[3] =0x74;

   SPI_TxBuf[4] =0xEF;

   SPI_TxBuf[5] =0x23;

 

   SPI0_pollTransfer(SPI_TxBuf, NULL, SPI0_TRANSFER_TX, 6);

 

}

 

 

How can I stop this from looping?

 

Hugues

 

Posts: 2,326
Registered: ‎10-14-2014

Re: EFM8UB10F16G-B-QFN20 - SPI0_pollTransfer loop

Would you like add a while in the end of the main routine to see if it make difference.

while (1)

{

;

}

WeiguoLu
Posts: 17
Registered: ‎05-15-2017

Re: EFM8UB10F16G-B-QFN20 - SPI0_pollTransfer loop

thanks @delu, adding the while loop solved my problem.

 

The MISO/MOSI inversion was due to the hardware.