24 #include <stm32/gpio.h>
25 #include <stm32/rcc.h>
26 #include <stm32/spi.h>
27 #include <stm32/misc.h>
28 #include <stm32/dma.h>
34 #define POWER_MODE (1 << 1 | 1)
35 #define SGL_DIF 1 // Single ended
37 #define ADS8344Unselect() GPIOB->BSRR = GPIO_Pin_12
38 #define ADS8344Select() GPIOB->BRR = GPIO_Pin_12
48 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
50 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
52 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
54 GPIO_InitTypeDef GPIO_InitStructure;
55 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
56 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
57 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
58 GPIO_Init(
GPIOB, &GPIO_InitStructure);
60 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
61 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
62 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
63 GPIO_Init(
GPIOB, &GPIO_InitStructure);
66 SPI_Cmd(SPI2, ENABLE);
67 SPI_InitTypeDef SPI_InitStructure;
68 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
69 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
70 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
71 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
72 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
73 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
74 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
75 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
76 SPI_InitStructure.SPI_CRCPolynomial = 7;
77 SPI_Init(SPI2, &SPI_InitStructure);
80 NVIC_InitTypeDef NVIC_init_struct = {
81 .NVIC_IRQChannel = DMA1_Channel4_IRQn,
82 .NVIC_IRQChannelPreemptionPriority = 0,
83 .NVIC_IRQChannelSubPriority = 0,
84 .NVIC_IRQChannelCmd = ENABLE
86 NVIC_Init(&NVIC_init_struct);
108 DMA_DeInit(DMA1_Channel4);
109 DMA_InitTypeDef DMA_initStructure_4 = {
110 .DMA_PeripheralBaseAddr = (
uint32_t)(SPI2_BASE + 0x0C),
112 .DMA_DIR = DMA_DIR_PeripheralSRC,
114 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
115 .DMA_MemoryInc = DMA_MemoryInc_Enable,
116 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
117 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
118 .DMA_Mode = DMA_Mode_Normal,
119 .DMA_Priority = DMA_Priority_VeryHigh,
120 .DMA_M2M = DMA_M2M_Disable
122 DMA_Init(DMA1_Channel4, &DMA_initStructure_4);
125 DMA_DeInit(DMA1_Channel5);
126 DMA_InitTypeDef DMA_initStructure_5 = {
127 .DMA_PeripheralBaseAddr = (
uint32_t)(SPI2_BASE + 0x0C),
129 .DMA_DIR = DMA_DIR_PeripheralDST,
131 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
132 .DMA_MemoryInc = DMA_MemoryInc_Enable,
133 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
134 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
135 .DMA_Mode = DMA_Mode_Normal,
136 .DMA_Priority = DMA_Priority_Medium,
137 .DMA_M2M = DMA_M2M_Disable
139 DMA_Init(DMA1_Channel5, &DMA_initStructure_5);
142 SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);
144 DMA_Cmd(DMA1_Channel4, ENABLE);
147 SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
149 DMA_Cmd(DMA1_Channel5, ENABLE);
152 DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, ENABLE);
165 DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, DISABLE);
167 SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, DISABLE);
168 SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, DISABLE);
170 DMA_Cmd(DMA1_Channel4, DISABLE);
171 DMA_Cmd(DMA1_Channel5, DISABLE);
void dma1_c4_irq_handler(void)
uint16_t ADS8344_values[NB_CHANNELS]
#define ADS8344Unselect()
static volatile uint8_t channel
Inertial Measurement Unit interface.
void imu_crista_arch_init(void)
static void ADS8344_read_channel(void)
static uint8_t buf_out[4]