新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2018-12-5
- 在线时间
- 45 小时
|
20金钱
使用F103C8T6控ad7124-8,原理图和手册中三线RTD测量配置一致,AIN0和AIN1各输出250uA,依次写了03、09、19、21、01寄存器,写入与最后读取寄存区都是和配置一样的,外面接了一个150欧电阻,按理应该在5.1K处应该能量到2.5V左右,但目前始终就是0.5V左右,请问是哪里配置出问题?这是SPI初始化,以及配置程序
{
HAL_Init();
SystemClock_Config();
MX_SPI1_Init();
HAL_Delay(500);
//reset
HAL_SPI_Transmit(&hspi1, wrBuf, 8, 1000);
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//CS0
// write[0] = 0x45;
// HAL_SPI_Transmit(&hspi1, write, 1, 1000);
// HAL_SPI_Receive(&hspi1,R_write, 1, 1000);
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);//CS1
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);//CS0
HAL_Delay(10);
write[0] = 0x03;
HAL_SPI_Transmit(&hspi1, write, 1, 1000); //写入 io control_1 寄存器
HAL_Delay(10);
write[0] = 0x00;
// write[1] = 0x9B;
write[1] = 0x24;
write[2] = 0x10;
HAL_SPI_Transmit(&hspi1, write, 3, 1000);
HAL_Delay(100);
write[0] = 0x09;
HAL_SPI_Transmit(&hspi1, write, 1, 1000); //写入 channel 0
HAL_Delay(10);
write[0] = 0x80;
write[1] = 0x43;
HAL_SPI_Transmit(&hspi1, write, 2, 1000);
HAL_Delay(100);
write[0] = 0x19;
HAL_SPI_Transmit(&hspi1, write, 1, 1000); //配置寄存器0 CONFIG_0
HAL_Delay(10);
write[0] = 0x09;
write[1] = 0xE5;
HAL_SPI_Transmit(&hspi1, write, 2, 1000);
HAL_Delay(100);
write[0] = 0x21;
HAL_SPI_Transmit(&hspi1, write, 1, 1000); //写入滤波寄存器寄存器,FILTER_0
HAL_Delay(10);
write[0] = 0x06;
write[1] = 0x00;
write[2] = 0x80;
HAL_SPI_Transmit(&hspi1, write, 3, 1000);
HAL_Delay(2000);
write[0] = 0x01;
HAL_SPI_Transmit(&hspi1, write, 1, 1000);
HAL_Delay(100);
// write[0] = 0x0D;
write[0] = 0x05;
// write[1] = 0x81;
write[1] = 0xC3;
HAL_SPI_Transmit(&hspi1, write, 2, 2000);
HAL_Delay(1000);
write[0] = 0x41;
HAL_SPI_Transmit(&hspi1, write, 1, 1000);
HAL_Delay(100);
R_write[0] = 0;
R_write[1] = 0;
HAL_SPI_Receive(&hspi1,R_write, 2, 1000);
HAL_Delay(1000);
void MX_SPI1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
// __HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE END SPI1_Init 1 */
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_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;//10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI1)
{
/* SPI1 clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
}
|
|