请问各位大佬,有没有可能我买了个坏的?这是我的接线,手头也没有示波器,不知道该怎么办
我的驱动代码如下:
#include <string.h>
#include "./SYSTEM/usart/usart.h"
#include "./SYSTEM/delay/delay.h"
#include "./BSP/ADIS/adis.h"
#include "./BSP/ADIS/adis_reg.h"
SPI_HandleTypeDef spi_handler;
TIM_HandleTypeDef timx_cap_dr_handle;
uint32_t Meas[6];
void ADIS_SPI_Init(void)
{
GPIO_InitTypeDef gpio_init_struct;
SPI1_SPI_CLK_ENABLE();
SPI1_SCK_GPIO_CLK_ENABLE();
SPI1_MISO_GPIO_CLK_ENABLE();
SPI1_MOSI_GPIO_CLK_ENABLE();
ADIS_CS_GPIO_CLK_ENABLE();
gpio_init_struct.Pin = SPI1_SCK_GPIO_PIN;
gpio_init_struct.Mode = GPIO_MODE_AF_PP;
gpio_init_struct.Pull = GPIO_NOPULL;
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_struct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(SPI1_SCK_GPIO_PORT, &gpio_init_struct);
gpio_init_struct.Pin = SPI1_MISO_GPIO_PIN;
HAL_GPIO_Init(SPI1_MISO_GPIO_PORT, &gpio_init_struct);
gpio_init_struct.Pin = SPI1_MOSI_GPIO_PIN;
HAL_GPIO_Init(SPI1_MOSI_GPIO_PORT, &gpio_init_struct);
gpio_init_struct.Pin = ADIS_CS_GPIO_PIN;
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(ADIS_CS_GPIO_PORT, &gpio_init_struct);
gpio_init_struct.Pin = ADIS_RST_GPIO_PIN;
HAL_GPIO_Init(ADIS_RST_GPIO_PORT, &gpio_init_struct);
ADIS_CS(0);
ADIS_RST(0);
delay_us(30);
ADIS_RST(1);
delay_ms(500);
spi_handler.Instance = SPI1_SPI;
spi_handler.Init.Mode = SPI_MODE_MASTER;
spi_handler.Init.Direction = SPI_DIRECTION_2LINES;
spi_handler.Init.DataSize = SPI_DATASIZE_16BIT;
spi_handler.Init.CLKPolarity = SPI_POLARITY_HIGH;
spi_handler.Init.CLKPhase = SPI_PHASE_2EDGE;
spi_handler.Init.NSS = SPI_NSS_SOFT;
spi_handler.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
spi_handler.Init.FirstBit = SPI_FIRSTBIT_MSB;
spi_handler.Init.TIMode = SPI_TIMODE_DISABLE;
spi_handler.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
spi_handler.Init.CRCPolynomial = 7;
HAL_SPI_Init(&spi_handler);
__HAL_SPI_ENABLE(&spi_handler);
}
void timx_capture_dr_init(uint32_t arr, uint16_t psc)
{
TIM_IC_InitTypeDef tim_ic_init_struct = {0};
GPIO_InitTypeDef gpio_init_struct = {0};
TIMX_DR_CLK_ENABLE();
TIMX_DR_GPIO_CLK_ENABLE();
gpio_init_struct.Pin = TIMX_DR_GPIO_PIN;
gpio_init_struct.Mode = GPIO_MODE_AF_PP;
gpio_init_struct.Pull = GPIO_PULLDOWN;
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_struct.Alternate = TIMX_DR_GPIO_AF;
HAL_GPIO_Init(TIMX_DR_GPIO_PORT, &gpio_init_struct);
HAL_NVIC_SetPriority(TIMX_DR_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(TIMX_DR_IRQn);
timx_cap_dr_handle.Instance = TIMX_DR;
timx_cap_dr_handle.Init.Prescaler = psc;
timx_cap_dr_handle.Init.CounterMode = TIM_COUNTERMODE_UP;
timx_cap_dr_handle.Init.Period = arr;
HAL_TIM_IC_Init(&timx_cap_dr_handle);
tim_ic_init_struct.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
tim_ic_init_struct.ICSelection = TIM_ICSELECTION_DIRECTTI;
tim_ic_init_struct.ICPrescaler = TIM_ICPSC_DIV1;
tim_ic_init_struct.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&timx_cap_dr_handle, &tim_ic_init_struct, TIMX_DR_CHX);
HAL_TIM_IC_Start_IT(&timx_cap_dr_handle, TIMX_DR_CHX);
}
void TIMX_DR_IRQHandler(void)
{
if (__HAL_TIM_GET_FLAG(&timx_cap_dr_handle, TIM_FLAG_CC1) != RESET)
{
__HAL_TIM_CLEAR_IT(&timx_cap_dr_handle, TIM_IT_CC1);
}
}
static uint16_t Imu_Config_Address[]={
(((uint16_t)(NULL_CNFG | WRITE_FLAG)) << 8) | (uint16_t)0x0A,
(((uint16_t)(NULL_CNFG+1 | WRITE_FLAG)) << 8) | (uint16_t)0x3F,
(((uint16_t)(DEC_RATE | WRITE_FLAG)) << 8) | (uint16_t)0x13,
(((uint16_t)(DEC_RATE+1 | WRITE_FLAG)) << 8) | (uint16_t)0x00,
};
void ADIS_SPI_Imu_Config(void)
{
uint16_t STAT = 0, Address = ((uint16_t)(DIAG_STAT | READ_FLAG)) << 8;
ADIS_SPI_ReadID();
}
static uint16_t Address_Meas[]={
((uint16_t)(X_GYRO_LOW | READ_FLAG)) << 8,
((uint16_t)(X_GYRO_OUT | READ_FLAG)) << 8,
((uint16_t)(Y_GYRO_LOW | READ_FLAG)) << 8,
((uint16_t)(Y_GYRO_OUT | READ_FLAG)) << 8,
((uint16_t)(Z_GYRO_LOW | READ_FLAG)) << 8,
((uint16_t)(Z_GYRO_OUT | READ_FLAG)) << 8,
((uint16_t)(X_ACCL_LOW | READ_FLAG)) << 8,
((uint16_t)(X_ACCL_OUT | READ_FLAG)) << 8,
((uint16_t)(Y_ACCL_LOW | READ_FLAG)) << 8,
((uint16_t)(Y_ACCL_OUT | READ_FLAG)) << 8,
((uint16_t)(Z_ACCL_LOW | READ_FLAG)) << 8,
((uint16_t)(Z_ACCL_OUT | READ_FLAG)) << 8,
(uint16_t)Address_Dummy
};
void ADIS_SPI_ReadMeasData(uint32_t *Meas)
{
uint16_t TempMeas[12] = {0};
SPI_READ_WRITE_16bit(Address_Meas[0]);
for (uint8_t i=0; i<12; i++) {
TempMeas[i] = SPI_READ_WRITE_16bit(Address_Meas[i+1]);
}
for (uint8_t i=0; i<6; i++) {
Meas[i] = ((uint32_t)TempMeas[i*2+1] << 16) | TempMeas[i*2];
}
}
uint8_t ADIS_SPI_ReadID(void)
{
uint16_t ID = 0, Address = ((uint16_t)(PROD_ID | READ_FLAG)) << 8;
uint8_t *tmp = (uint8_t *)&Address;
SPI_READ_WRITE_16bit(Address);
SPI_READ_WRITE_16bit(Address);
ID = SPI_READ_WRITE_16bit(Address_Dummy);
if(ID != ADIS16465_ID) {
printf("检测不到ADIS16465模块,请检查接线 ID:0x%X\n", ID); return 0;
}
else {
printf("ADIS16465模块,ID:0x%X\n", ID);
}
return 1;
}
uint16_t SPI_READ_WRITE_16bit(uint16_t txdata)
{
uint16_t rxdata = 0;
HAL_SPI_TransmitReceive(&spi_handler, (uint8_t*)&txdata, (uint8_t*)&rxdata, 1, SPIT_FLAG_TIMEOUT);
delay_us(Stall_Time_US);
return rxdata;
}