Question
I'm trying to communicate between the STM32F107VC (master mode) and a TDC GP22 slave chip but came across this issue:I'm expecting to read 0x12 but i always get 0xFF, plese help me my email: amiryal.me@gmail.com
gp22_send_1byte(Power_On_Reset);
HAL_Delay(1);
gp22_wr_config_reg(0x81, reg_test);
HAL_Delay(1);
//gp22_send_1byte(init);
HAL_SPI_Transmit(&hspi3, &tx, 1, 1); //send tx=0xb5 opcode
HAL_Delay(1);
HAL_SPI_Receive(&hspi3, &recive, 1, 1); // store in uint8_t rx
HAL_Delay(1);
data_buf2 = (reg_test>>24)&0xff ;
if(recive==data_buf2){
printf ("OK");
}
else{
printf ("NO");
}
HAL_Delay(50);
}
..............................................................................................................................
void gp22_wr_config_reg (uint8_t opcode_address,uint32_t config_reg_data)
{
uint8_t Data_Byte_Lo = config_reg_data;
uint8_t Data_Byte_Mid1 = config_reg_data>>8;
uint8_t Data_Byte_Mid2 = config_reg_data>>16;
uint8_t Data_Byte_Hi = config_reg_data>>24;
//uint8_t common_delay = 10; // important delay (16) at SPI freq.=750kHz
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi3,&opcode_address,1,1);
HAL_Delay(1);
HAL_SPI_Transmit(&hspi3,&Data_Byte_Hi,1,1);
HAL_Delay(1);
HAL_SPI_Transmit(&hspi3,&Data_Byte_Mid2,1,1);
HAL_Delay(1);
HAL_SPI_Transmit(&hspi3,&Data_Byte_Mid1,1,1);
HAL_Delay(1);
// DATA LOW
HAL_SPI_Transmit(&hspi3,&Data_Byte_Lo,1,1);
//Simple_delay_750ns((void*)common_delay);
HAL_Delay(1);
// Reset to device SPIx
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
}
............................................................................................................................
void gp22_send_1byte (uint8_t gp22_opcode_byte)
{
// Deactivating Reset SPIx
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_RESET);
//while(__HAL_SPI_GET_FLAG(&hspi3,SPI_FLAG_TXE)==0){}
HAL_SPI_Transmit(&hspi3,&gp22_opcode_byte,1,1);
//Simple_delay_750ns((void*)10);
HAL_Delay(1);
//DWT_Delay_us (8);
// OPCODE TO Device
// important delay (16) at SPI freq.=750kHz
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);
// Reset to device SPIx
}

