Hello Guys,
On my custom design board, there are a STM32F767ZI microprocessor and a HV2901 Analog Switch IC. My plan is that with controlling HV2901, already generated signal should flow the other components on my board. I have two questions. One of them is defining variables, so how can I fix the errors in this part. The other one is that I define SPI as full duplex master. How can I write codes for receiving data?
Here is my code;
const uint8_t testdata_out; // Main signal which will flow through ON-switch to other part of the circuit
const uint32_t switch_output={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // I try to define which switch should ON. Based on data // sheet, for first switch, DO should 1.
uint16_t SW_Out_1; // In CubeMX, there is only option for setting 16-bit data as maximum
uint16_t SW_Out_2; // In CubeMX, there is only option for setting 16-bit data as maximum
uint32_t SW_Out = (SW_Out_1>>16) | (SW_Out_2<<16); // HV2901 needs 32 bit data length for controlling switch positions, so I merged previous //variables as 32-bit.
// Latch or SYNC Pin needs to LOW
HAL_GPIO_WritePin(LE_Pin_GPIO_Port, LE_Pin_Pin, GPIO_PIN_RESET);
// Write data with SPI
SW_Out = switch_output<<1 | testdata_out<<31;
HAL_SPI_Transmit(&hspi4,(uint8_t *)&SW_Out,32,100);
// When data is ready, LATCH will high
HAL_GPIO_WritePin(LE_Pin_GPIO_Port, LE_Pin_Pin, GPIO_PIN_SET);