uranyumx
Advanced Member level 4
Hello,
I try to control MCP41100 with SMT32F767. I enabled the SPI4 in transmit only master mode in CubeMX. Then I write a code in Keil IDE like in the below. I got 212.5mV output from wiper even I set to different values of Bias_Data_2 variables. Where do I make a mistake of control this POT?
Thank you,
Code in Keil:
CubeMX Settings:
I try to control MCP41100 with SMT32F767. I enabled the SPI4 in transmit only master mode in CubeMX. Then I write a code in Keil IDE like in the below. I got 212.5mV output from wiper even I set to different values of Bias_Data_2 variables. Where do I make a mistake of control this POT?
Thank you,
Code in Keil:
Code:
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);
}
CubeMX Settings:
Code:
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 */
}