This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS3in1/1.Cabin/1.Software/STM32_ADS1278/Drivers/BSP/ADS1278/ADS1278.c

93 lines
2.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "./BSP/ADS1278/ADS1278.h"
void ADS1278_Init(void){
GPIO_InitTypeDef GPIO_InitStruct;
ADS1278_DRDY_GPIO_CLK_ENABLE(); /*DRDY引脚时钟使能*/
ADS1278_FORMAT_GPIO_CLK_ENABLE(); /*FORMAT引脚时钟使能*/
ADS1278_SYNC_GPIO_CLK_ENABLE(); /*SYNC引脚时钟使能*/
/*DRDY引脚设置为下降沿中断*/
GPIO_InitStruct.Pin = ADS1278_DRDY_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(ADS1278_DRDY_GPIO_Port, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
/*FORMAT设置为高电平输出*/
GPIO_InitStruct.Pin = ADS1278_FORMAT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(ADS1278_FORMAT_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(ADS1278_FORMAT_GPIO_Port, ADS1278_FORMAT_Pin, GPIO_PIN_SET);
/*SYNC设置为普通输出初始为高电平*/
GPIO_InitStruct.Pin = ADS1278_SYNC_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(ADS1278_SYNC_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_WritePin(ADS1278_SYNC_GPIO_Port, ADS1278_SYNC_Pin, GPIO_PIN_SET);
}
void ADS1278_Reset(void){
/*SYNC拉低至少1个CLK周期*/
HAL_GPIO_WritePin(ADS1278_SYNC_GPIO_Port, ADS1278_SYNC_Pin, GPIO_PIN_RESET);
delay_ms(1);
HAL_GPIO_WritePin(ADS1278_SYNC_GPIO_Port, ADS1278_SYNC_Pin, GPIO_PIN_SET);
}
uint8_t DataBuffer[300];
int num = 0;
void ADS1278_Read_Data(void){
uint8_t ReceiveDataArrary[24]; /*接收数据数组*/
HAL_SPI_Receive(&g_spi1_handler, ReceiveDataArrary, 24, 1000); /*接收数据*/
DataBuffer[num+0]= ReceiveDataArrary[21];
DataBuffer[num+1]= ReceiveDataArrary[22];
DataBuffer[num+2]= ReceiveDataArrary[23];
num += 3;
if(num >= 240){
/* 暂停采集 */
HAL_GPIO_WritePin(ADS1278_SYNC_GPIO_Port, ADS1278_SYNC_Pin, GPIO_PIN_RESET);
printf("\r\n开始\r\n");
for(int i=0; i<240;i++){
printf("%d\r\n",DataBuffer[i]);
}
printf("\r\n结束\r\n");
/* 继续采集 */
HAL_GPIO_WritePin(ADS1278_SYNC_GPIO_Port, ADS1278_SYNC_Pin, GPIO_PIN_SET);
num = 0;
}
}
uint8_t SYNC_Flag = 0;
/*DRDY下降沿中断函数*/
void EXTI15_10_IRQHandler(void)
{
if(__HAL_GPIO_EXTI_GET_IT(ADS1278_DRDY_Pin) != RESET)
{
//清除中断标志位
__HAL_GPIO_EXTI_CLEAR_IT(ADS1278_DRDY_Pin);
if(SYNC_Flag == 0){
/* 上电第一次出现数据复位ADS1278重新计数 */
ADS1278_Reset();
SYNC_Flag = 1;
}
else{
/* 开始接收数据 */
ADS1278_Read_Data();
}
}
}