This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Afe031 programming and receiving data

Other Parts Discussed in Thread: AFE031

hi, i'm trying to comunicate with an AFE031, i would like to understand how receive data from the spi, if i need a cycle of reading after one of sending data. 

here is the code i wrote:

#include "inc/hw_types.h" 																		
#include "inc/hw_gpio.h"																	
#include "inc/hw_ints.h" 																	
#include "inc/hw_memmap.h" 																		
#include "driverlib/sysctl.h" 																	
#include "driverlib/interrupt.h" 																
#include "driverlib/rom_map.h" 																	
#include "driverlib/gpio.h" 																	
#include "driverlib/timer.h" 																	
#include "driverlib/ssi.h"																		
#include "driverlib/pin_map.h" 																	

#include "utils/uartstdio.h"
#include "driverlib/uart.h"

#define PINDAC GPIO_PORTA_BASE,GPIO_PIN_6

unsigned long DataRx[1];					

		
void ConfigureUART(void);

int main(void) {

	
	SysCtlClockSet(
			SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ
					| SYSCTL_OSC_MAIN); 						// Clock setting

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); 		//Abilita la porta A
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); 	//Abilita periferica SSI0

	ConfigureUART();
	
	GPIOPinConfigure(GPIO_PA4_SSI0RX); 
	GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_4); 

	GPIOPinConfigure(GPIO_PA3_SSI0FSS); 
	GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3); 

	GPIOPinConfigure(GPIO_PA2_SSI0CLK); 
	GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2); 

	GPIOPinConfigure(GPIO_PA5_SSI0TX); 
	GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5); 

	
	SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
			SSI_MODE_MASTER, 10000, 16);
	SSIEnable(SSI0_BASE);



	GPIOPinTypeGPIOOutput(PINDAC);

	unsigned long rxdata;

	UARTprintf("test\n");

	SSIDataPut(SSI0_BASE, 0x8200);
	SysCtlDelay(13333);
	SSIDataGet(SSI0_BASE, &DataRx[0]);
	SSIDataPut(SSI0_BASE, 0x0000);
	SSIDataGet(SSI0_BASE, &DataRx[0]);
	while (SSIBusy(SSI0_BASE))
		;
	UARTprintf("DieRev: %X\n", DataRx[0]);

//	SSIDataPut(SSI0_BASE, 0x8A00);
//	while (SSIBusy(SSI0_BASE))
//		;
//	SSIDataGet(SSI0_BASE, &DataRx[0]);
//	UARTprintf("DieRev: %X\n", DataRx[0]);

	while (1) { 					

	}

}


void ConfigureUART(void) {
	//
	// Enable the GPIO Peripheral used by the UART.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Enable UART0
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

	//
	// Configure GPIO Pins for UART mode.
	//
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Use the internal 16MHz oscillator as the UART clock source.
	//
	UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

	//
	// Initialize the UART for console I/O.
	//
	UARTStdioConfig(0, 115200, 16000000);
	//
	UARTStdioConfig(0, 115200, 16000000);
}

thanks

  • Hello Giuseppe Giancola1,

    There are two modes of operation for the AFE031: a) SPI mode and b) DAC mode.

    SPI transactions in SPI mode are 16-bit operations whereas in DAC mode only 10-bits are shifted into the AFE031 SPI interface.

    SPI mode is used to program registers inside the AFE031 and to read their content. In order to properly read a register from the AFE031 it is necessary to perform two consecutive read operations. The first read operation contains the address of the register that you want to read, the second read operation is needed to shift out the contents of the register being polled (such contents can be captured from the DOUT line).

    Hope this helps. Best regards and happy holiday season!

    Jose

  • hi, thanks for the answer, i tried what you said, but the answers of the afe seems to be random, for example i try to read the 0x02 register(gain select) that by default is set to 0x32, so I send two 0x8200 instructions, but i obtain 8202.

    in the image attached you can see the oscilloscope images and the the putty serial answers

    thanks!

    it seems to answer laso with 0xXX02

    if i send 0x8b00 i obtain 8b02

    thanks and Merry Christmas!!!

  • Hello Giuseppe,

    I do not know why you are receiving incorrect data during SPI read. I performed a read operation onto the Gain Select register, below is the result I obtained.

    The latest screen capture in your post is different from the original one. The original screenshot you posted (included below for everyone’s reference) did not exhibit the 0x??02 phenomenon you describe.

    Could you try to capture the SPI voltages using a different oscilloscope?

    Best,

    Jose

  • hi, thanks for your answer,

    I obtained 8200 because the afe wasn't supplied so instead to write another post i changed the image