uint16_t ADIS_ReadReg(uint8_t reg) { uint32_t a; uint8_t in[4]; uint8_t out[4]; /* write the reg address */ out[0] = (ADIS_READ | (reg & ADIS_REG_MASK)); out[1] = 0; out[2] = 0; out[3] = 0; ADIS_CS_WRITE(Bit_RESET); ADIS_SendBuf(&out[0], &in[0], 2); ADIS_CS_WRITE(Bit_SET); a = 500; while (a) a--; ADIS_CS_WRITE(Bit_RESET); ADIS_SendBuf(&out[0], &in[0], 2); ADIS_CS_WRITE(Bit_SET); return in[0] << 8 | in[1]; }
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; // PA1 - MIC GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed = 0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; // analog input GPIO_Init (GPIOA, &GPIO_InitStructure); // PA0 - WAKEUP button GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // PA3 - ADIS reset, PA4 - nRF Chip Select GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // PB2 - LCD_DC, PB10 - ADIS_CS GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // output push-pull GPIO_Init(GPIOB, &GPIO_InitStructure); // PB5 - SENS_INT GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // input pull-down GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); // PC12 - LED, PC7 - LCD_RES, PC8 - nRF CE, PC10 - LCD_E GPIO_WriteBit(GPIOC,GPIO_Pin_12,Bit_SET); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // output push-pull GPIO_Init(GPIOC, &GPIO_InitStructure); // PC13 - TAMP button, PC6 -Joy Center, PC9 - nRF IRQ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_6 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // input floating GPIO_Init(GPIOC, &GPIO_InitStructure); // PC5 - Joystick GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = 0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; // analog input GPIO_Init (GPIOC, &GPIO_InitStructure); // Configure USB pull-up pin GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_Init(GPIOC, &GPIO_InitStructure); NRF_CS_WRITE(Bit_SET); NRF_CE_WRITE(Bit_RESET); ADIS_CS_WRITE(Bit_SET); ADIS_RESET_WRITE(Bit_SET); }