尊敬的技术大大们好!我遇到的情况是这样子的,软件复位以后,往SPI_CONFIG寄存器写入数值0x0004,我们可以看到正常的数值0x0004,意味着器件已经脱离低功耗模式。同时我尝试读取REG_DEVICEID也可以读取到正确的版本信息,这证明我的SPI读写应该是配置正确了。以下这是我的SPI配置,它应该没有错
static void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
/* USER CODE BEGIN SPI1_Init 1 */
/* USER CODE END SPI1_Init 1 */
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
我的问题是,当我往DACx data register寄存器写入数值的时候总是无效,只能读取到0x0000
cs_sw(chipIndex);
dac_writeReg(0x0E, 0x000A);
HAL_Delay(5);
dac_writeReg(R_SPICONFIG, 0x0004);
uart2_printf("delayreg:%x\r\n",dac_readReg(R_SPICONFIG));
uart2_printf("id:%x\r\n",dac_readReg(0x01));
{
cs_sw(chipIndex);
dac_writeReg(R_DACRANGE0, 0x0000);
dac_writeReg(R_DACRANGE1, 0x0000);
dac_writeReg(R_DACRANGE2, 0x0000);
dac_writeReg(R_DACRANGE3, 0x0000);
dac_writeReg(R_DACPWDWN, 0x0000);
dac_writeReg(R_GENCONFIG,0x0400);
dac_writeReg(R_BRDCONFIG, 0x0000);
dac_writeReg(R_SYNCCONFIG,0x0000);
dac_writeReg(0x10, 0x6666);
dac_writeReg(R_DACPWDWN, 0x0000);
}
我在1秒定时器里头添加了写完再读寄存器输出的代码,但是读取到的数值一直为0
void Timer2_Callback(TIM_HandleTypeDef* htim)
{
(void)htim;
static uint8_t toggleF = 0;
toggleF ^= 0x01;
HAL_GPIO_WritePin(powderBlueLED_GPIO_Port, powderBlueLED_Pin, (toggleF==0x00)?GPIO_PIN_RESET:GPIO_PIN_SET);
//dac_init(&hspi1);
uint8_t index = 0;
cs_sw(0);//im sure it points to the cs pin im using
for(index = 0;index < 16;index++)
{
dac_writeReg(0x10+index, 0x6666);
uart2_printf("0x%x:0x%x\r\n",0x10+index,dac_readReg(0x10+index));
}
}
另外在软件复位前spiconfig寄存器一直无法正常写入,读取到的数值一直是0x0aa4,往TRIGGER register(offset = 0x0E)使能SOFT-RESET就可以解决,我看到好像没有人遇到这样子的问题,所以我顺带记录在这里希望可以帮到某些朋友。