2018-12-28 06:36 AM
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
}
2018-12-28 06:36 AM
I'm expecting to read 0x12 but i always get 0xFF,I write to register 1 the value 0x12345678 And when i do the test by sending the opcode 0xB5, i should receive the highest 8 bits from that value (0x12).and i any thing write in reg1 i always recivce 0xff,i once replace my tdc_gp22 with a new one, but dont corrected,Where is my mistake? im very confused and tired,plese help me
2018-12-28 08:45 AM
Review the signal with a scope or logic analyzer. Understand if you're battling an issue on the STM32 or GP22
I suspect you need a delay after raising the chip select. I would use the TransmitReceive form to pull back data. Data sheet doesn't indicate the need for waits between single bytes.
2018-12-28 01:05 PM
Use an oscilloscope to look at NSS, MISO, MOSI and SCK and compare with datasheets.