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.

AFE4300: AFE4300 SPI read write issue

Part Number: AFE4300

I have a problem in getting the ti AFE4300 start the ADC measurement. I started with a new board that was designed using reference design on TI. Am trying to communicate with the board through an stm32f103rbt6.

I was set up spi mode 1 and want to use body composition measurement (BCM).

I give 1mHz to afe 4300 board by arm pwm signal.

These are what has happened

1. I can not read ADC data result register. 

2. the RDY pin status unchanged. it keep high status.

 

 

int main()
{
SystemInit();
UART2_Init();
DelayInit();
PWM_Init();



RESET_init();
init_spi1();

resetAFE4300();
initAFE4300();
initBCM();

//
while(1)
{


if(GPIO_ReadInputDataBit(GPIOC,PIN_DRDY) == 1){

printf("register_Name\n\r");
printf("0x%X\n\r",readRegister(ADC_DATA_RESULT));
printf("0x%X\n\r",readRegister(ADC_CONTROL_REGISTER));
printf("0x%X\n\r",readRegister(MISC1_REGISTER));
printf("0x%X\n\r",readRegister(MISC2_REGISTER));
printf("0x%X\n\r",readRegister(DEVICE_CONTROL_1));
printf("0x%X\n\r",readRegister(ISW_MATRIX));
printf("0x%X\n\r",readRegister(VSW_MATRIX));
printf("0x%X\n\r",readRegister(IQ_MODE_ENABLE));
printf("0x%X\n\r",readRegister(WEIGHT_SCALE_CONTROL));
printf("0x%X\n\r",readRegister(BCM_DAC_FREQ));
printf("0x%X\n\r",readRegister(DEVICE_CONTROL_2));
printf("0x%X\n\r",readRegister(ADC_CONTROL_REGISTER_2));
printf("0x%X\n\r",readRegister(MISC3_REGISTER));

}
else if(GPIO_ReadInputDataBit(GPIOC,PIN_DRDY) == 0){
//printf("%0x\n\r",readRegister(ADC_DATA_RESULT));
printf("low\n\r");
}
DelayMs(100);
}
}

void RESET_init(void){
GPIO_InitTypeDef GPIO_InitStructure;

//GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

/* Enable the GPIO Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

/* Configure the GPIO pin */
GPIO_InitStructure.GPIO_Pin = PIN_RESET;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure); 

GPIO_InitStructure.GPIO_Pin = SPI_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = PIN_DRDY;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//
GPIO_SetBits(GPIOA, GPIO_Pin_4);
}

uint32_t RDY_read(void){
return GPIO_ReadInputDataBit(GPIOC,PIN_DRDY);
}

void RESET_HIGH(void){
//GPIOA->BSRR = PIN_RESET; 
GPIO_SetBits(GPIOC,PIN_RESET);
}

void RESET_LOW(void){
//GPIOA->BRR = PIN_RESET; 

GPIO_ResetBits(GPIOC,PIN_RESET);
}

void resetAFE4300(void){
RESET_LOW();
//printf("111");
DelayMs(100);
RESET_HIGH();
}


void init_spi1(void){ // for MASTER mode
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
// GPIO_StructInit (& GPIO_InitStructure);
// SPI_StructInit (& SPI_InitStructure);

/* Enable GPIOs clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

/* Enable SPI clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

/* Configure SPI SCK pin */ 
GPIO_InitStructure.GPIO_Pin = SPI_SCK_PIN | SPI_MOSI_PIN | SPI_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);


/* SPI configuration -------------------------------------------------------*/

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; //32
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);

/* Enable SPI */
SPI_Cmd(SPI1, ENABLE);

}

void writeRegister(unsigned char address, unsigned int data){
unsigned char firstByte = (unsigned char)(data >> 8);
unsigned char secondByte = (unsigned char)data; 

GPIO_ResetBits(GPIOA, GPIO_Pin_4);

SPI_SendByte(address);

SPI_SendByte(firstByte);
SPI_SendByte(secondByte);

GPIO_SetBits(GPIOA, GPIO_Pin_4);
}

int readRegister(unsigned char address){

int spiReceive = 0;
uint8_t spiReceiveFirst = 0;
uint8_t spiReceiveSecond = 0;

address = address & 0x1F; //Last 5 bits specify address
address = address | 0x20; //First 3 bits need to be 001 for read opcode

GPIO_ResetBits(GPIOA, GPIO_Pin_4); 

SPI_SendByte(address);
spiReceiveFirst = SPI_SendByte(0x00);
spiReceiveSecond = SPI_SendByte(0x00);

GPIO_SetBits(GPIOA, GPIO_Pin_4);

spiReceive = (spiReceiveFirst << 8);
spiReceive |= spiReceiveSecond;

return spiReceive;
}


void initAFE4300(void)
{
writeRegister(ADC_CONTROL_REGISTER,0x5140);
writeRegister(MISC1_REGISTER,0x0000); //
writeRegister(MISC2_REGISTER,0xFFFF); //
writeRegister(DEVICE_CONTROL_1,0x0004); //Power down both signal chains
writeRegister(ISW_MATRIX,0x0000);
writeRegister(VSW_MATRIX,0x0000);
writeRegister(IQ_MODE_ENABLE,0x0000); //
writeRegister(WEIGHT_SCALE_CONTROL,0x0000);
writeRegister(BCM_DAC_FREQ,0x0040); //
writeRegister(DEVICE_CONTROL_2,0x0000);
writeRegister(ADC_CONTROL_REGISTER_2,0x0011);
writeRegister(MISC3_REGISTER,0x00C0);
}

void initBCM(void)
{
writeRegister(ADC_CONTROL_REGISTER,0x4120); //Differential measurement mode, 32 SPS //4120//C1A0
writeRegister(DEVICE_CONTROL_1,0x0006); //Power up BCM signal chain
writeRegister(ISW_MATRIX,0x0408); //Channels IOUTP1 and IOUTN0
writeRegister(VSW_MATRIX,0x0408); //Channels VSENSEP1 and VSENSEN0
writeRegister(ADC_CONTROL_REGISTER_2,0x0063); //ADC selects output of BCM-I output
writeRegister(WEIGHT_SCALE_CONTROL,0x0000); //Gain = 1 DAC Offset = 0 0x603F
writeRegister(BCM_DAC_FREQ,0x0032);
writeRegister(MISC3_REGISTER,0x0030);
}

uint8_t SPI_SendByte(uint8_t Data)
{
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, Data); 
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

return SPI_I2S_ReceiveData(SPI1);
}

Any leads would be of great help

  • Hi Ram,

    Can you please first verify SPI write ? You can measure VLDO voltage before and after enabling the weight scale signal chain.
    If you do not observe the change in VLDO, then your SPI write is not happening. To debug this please verify ( and share) all the SPI signals by probing them using analog oscilloscope.

    Regards,
    Prabin