uint8_t Data_Bias[1];
uint16_t Bias_Data_2;
uint8_t Bias_Write = 0x13;
uint16_t Bias_Buf;
...
while (1)
{
Bias_Data_2 = 255;
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_RESET);
Bias_Buf = Bias_Write<<8 | Bias_Data_2;
HAL_SPI_Transmit(&hspi4,(uint8_t*)&Bias_Buf,2,100);
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_SET);
}
static void MX_SPI4_Init(void)
{
/* USER CODE BEGIN SPI4_Init 0 */
/* USER CODE END SPI4_Init 0 */
/* USER CODE BEGIN SPI4_Init 1 */
/* USER CODE END SPI4_Init 1 */
/* SPI4 parameter configuration*/
hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_16BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi4.Init.NSS = SPI_NSS_SOFT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi4.Init.CRCPolynomial = 7;
hspi4.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi4.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI4_Init 2 */
/* USER CODE END SPI4_Init 2 */
}
Bias_Data_2=30;
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_RESET); //CS is LOW
Bias_Buf = Bias_Write<<8 | Bias_Data_2;
HAL_SPI_Transmit(&hspi4,(uint8_t*)&Bias_Buf,2,100);
//HAL_Delay(10);
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_SET); //CS is HIGH
int main (void)
{
/* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_RESET);
HAL_Delay(10);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
uint8_t Bias_Buf[2];
Bias_Buf[0]=0x13;
Bias_Buf[1]=0x40;
HAL_SPI_Transmit(&hspi4,(uint8_t*)&Bias_Buf,2,100);
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_SET);
}
}
Code:
int main (void)
{
uint8_t Bias_Buf[2];
Bias_Buf[0]=0x13;
Bias_Buf[1]=0x40;
while (1)
{
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi4, &Bias_Buf, 2, 100);
HAL_GPIO_WritePin(BIAS_CS_GPIO_Port, BIAS_CS_Pin, GPIO_PIN_SET);
HAL_Delay(10);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?