static void adc_setup(void) { gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO0); gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO1); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single conversion. */ adc_disable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); adc_disable_external_trigger_regular(ADC1); adc_set_right_aligned(ADC1); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_power_on(ADC1); /* Wait for ADC starting up. */ int i; for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); adc_reset_calibration(ADC1); adc_calibration(ADC1); }
static void adc_setup(void) { int i; rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single timer triggered injected conversion. */ adc_disable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); /* We can only use discontinuous mode on either the regular OR injected channels, not both */ adc_disable_discontinuous_mode_regular(ADC1); adc_enable_discontinuous_mode_injected(ADC1); /* We want to start the injected conversion with the TIM2 TRGO */ adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO); adc_set_right_aligned(ADC1); /* We want to read the temperature sensor, so we have to enable it. */ adc_enable_temperature_sensor(ADC1); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_power_on(ADC1); /* Wait for ADC starting up. */ for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); adc_reset_calibration(ADC1); while ((ADC_CR2(ADC1) & ADC_CR2_RSTCAL) != 0); adc_calibration(ADC1); while ((ADC_CR2(ADC1) & ADC_CR2_CAL) != 0); }
static void adc_setup(void) { int i; rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single conversion. */ adc_disable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); adc_disable_external_trigger_regular(ADC1); adc_set_right_aligned(ADC1); /* We want to read the temperature sensor, so we have to enable it. */ adc_enable_temperature_sensor(ADC1); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_power_on(ADC1); /* Wait for ADC starting up. */ for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); adc_reset_calibration(ADC1); adc_calibration(ADC1); }
void adc_setup(void) { rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO6); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO5 | GPIO1); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single conversion. */ adc_disable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); adc_disable_external_trigger_regular(ADC1); adc_set_right_aligned(ADC1); //adc_enable_temperature_sensor(ADC1); //adc_set_injected_offset(ADC1, 0x2, 0x00); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_power_on(ADC1); /* Wait for ADC starting up. */ delay_ms(170); adc_reset_calibration(ADC1); adc_calibration(ADC1); }
static void adc_setup(void) { int i; rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single timer triggered injected conversion with interrupt generation. */ /* While not needed for a single channel, try out scan mode which does all channels in one sweep and * generates the interrupt/EOC/JEOC flags set at the end of all channels, not each one. */ adc_enable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); /* We want to start the injected conversion with the TIM2 TRGO */ adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO); /* Generate the ADC1_2_IRQ */ adc_enable_eoc_interrupt_injected(ADC1); adc_set_right_aligned(ADC1); /* We want to read the temperature sensor, so we have to enable it. */ adc_enable_temperature_sensor(ADC1); adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_power_on(ADC1); /* Wait for ADC starting up. */ for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); adc_reset_calibration(ADC1); while ((ADC_CR2(ADC1) & ADC_CR2_RSTCAL) != 0); adc_calibration(ADC1); while ((ADC_CR2(ADC1) & ADC_CR2_CAL) != 0); }
/** * Configure a specific adc. */ void adc_config(uint32_t adc, const uint8_t const *channel_array) { adc_enable_scan_mode(adc); adc_set_continuous_conversion_mode(adc); adc_set_right_aligned(adc); adc_enable_external_trigger_regular(adc, ADC_CR2_EXTSEL_SWSTART); adc_set_sample_time_on_all_channels(adc, ADC_SAMPLE_TIME); adc_enable_dma(adc); adc_power_on(adc); { int i; /* Wait a bit for the adc to power on. */ for (i = 0; i < 800000; i++) { __asm("nop"); } } adc_reset_calibration(adc); adc_calibration(adc); adc_set_regular_sequence(adc, ADC_RAW_SAMPLE_COUNT/2, (uint8_t *)channel_array); }
int main(void) { clock_setup(); gpio_setup(); systick_setup(); adc_off(ADC1); usart_enable_all_pins(); usart_console_setup(); printf("hello!\n"); // power up the RHT chip... dht_power(true); delay_ms(2000); setup_tim7(); platform_simrf_init(); // interrupt pin from mrf platform_mrf_interrupt_enable(); simrf_soft_reset(); simrf_init(); simrf_immediate_sleep(); simrf_pan_write(0xcafe); uint16_t pan_sanity_check = simrf_pan_read(); printf("pan read back in as %#x\n", pan_sanity_check); simrf_address16_write(0x1111); adc_power_on(ADC1); adc_reset_calibration(ADC1); adc_calibration(ADC1); jack_setup(&jack1, &state.jack_machine1); jack_setup(&jack2, &state.jack_machine2); //state.rf_dest_id = 0x4202; state.rf_dest_id = 0x1; while (1) { struct jacks_result_t jr1, jr2; simrf_check_flags(NULL, &handle_tx); loop_forever(); jack_run_task(&state.jack_machine1, &jr1); if (jr1.ready) { printf("Channel 1 result: %d\n", jr1.value); } jack_run_task(&state.jack_machine2, &jr2); if (jr2.ready) { printf("Channel 2 result: %d\n", jr2.value); } task_send_data(&state); __WFI(); } return 0; }
/** * Enable selected channels on specified ADC. * Usage: * * adc_init_single(ADC1, 1, 1, 0, 0); * * ... would enable ADC1, enabling channels 1 and 2, * but not 3 and 4. */ static inline void adc_init_single(uint32_t adc, uint8_t chan1, uint8_t chan2, uint8_t chan3, uint8_t chan4) { uint8_t num_channels, rank; uint8_t channels[4]; // Paranoia, must be down for 2+ ADC clock cycles before calibration adc_off(adc); /* enable adc clock */ if (adc == ADC1) { #ifdef USE_AD1 num_channels = NB_ADC1_CHANNELS; ADC1_GPIO_INIT(); #endif } else if (adc == ADC2) { #ifdef USE_AD2 num_channels = NB_ADC2_CHANNELS; ADC2_GPIO_INIT(); #endif } /* Configure ADC */ /* Explicitly setting most registers, reset/default values are correct for most */ /* Set CR1 register. */ /* Clear AWDEN */ adc_disable_analog_watchdog_regular(adc); /* Clear JAWDEN */ adc_disable_analog_watchdog_injected(adc); /* Clear DISCEN */ adc_disable_discontinuous_mode_regular(adc); /* Clear JDISCEN */ adc_disable_discontinuous_mode_injected(adc); /* Clear JAUTO */ adc_disable_automatic_injected_group_conversion(adc); /* Set SCAN */ adc_enable_scan_mode(adc); /* Enable ADC<X> JEOC interrupt (Set JEOCIE) */ adc_enable_eoc_interrupt_injected(adc); /* Clear AWDIE */ adc_disable_awd_interrupt(adc); /* Clear EOCIE */ adc_disable_eoc_interrupt(adc); /* Set CR2 register. */ /* Clear TSVREFE */ adc_disable_temperature_sensor(adc); /* Clear EXTTRIG */ adc_disable_external_trigger_regular(adc); /* Clear ALIGN */ adc_set_right_aligned(adc); /* Clear DMA */ adc_disable_dma(adc); /* Clear CONT */ adc_set_single_conversion_mode(adc); rank = 0; if (chan1) { adc_set_sample_time(adc, adc_channel_map[0], ADC_SMPR1_SMP_41DOT5CYC); channels[rank] = adc_channel_map[0]; rank++; } if (chan2) { adc_set_sample_time(adc, adc_channel_map[1], ADC_SMPR1_SMP_41DOT5CYC); channels[rank] = adc_channel_map[1]; rank++; } if (chan3) { adc_set_sample_time(adc, adc_channel_map[2], ADC_SMPR1_SMP_41DOT5CYC); channels[rank] = adc_channel_map[2]; rank++; } if (chan4) { adc_set_sample_time(adc, adc_channel_map[3], ADC_SMPR1_SMP_41DOT5CYC); channels[rank] = adc_channel_map[3]; } adc_set_injected_sequence(adc, num_channels, channels); #if USE_AD_TIM4 #pragma message "Info: Using TIM4 for ADC" adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM4_TRGO); #elif USE_AD_TIM1 #pragma message "Info: Using TIM1 for ADC" adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM1_TRGO); #else #pragma message "Info: Using default TIM2 for ADC" adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM2_TRGO); #endif /* Enable ADC<X> */ adc_power_on(adc); /* Enable ADC<X> reset calibaration register */ adc_reset_calibration(adc); /* Check the end of ADC<X> reset calibration */ while ((ADC_CR2(adc) & ADC_CR2_RSTCAL) != 0); /* Start ADC<X> calibaration */ adc_calibration(adc); /* Check the end of ADC<X> calibration */ while ((ADC_CR2(adc) & ADC_CR2_CAL) != 0); } // adc_init_single
int main(void) { NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x3000); set_msi(); DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STANDBY | DBGMCU_STOP, DISABLE); set_bor(); Power.sleep_now=DISABLE; DataUpdate.Need_erase_flash=ENABLE; Settings.Geiger_voltage=360; // Напряжение на датчике 360 вольт Settings.Pump_Energy=350; // энергия накачки 350 мТл DataUpdate.current_flash_page=0; io_init(); // Инициализация потров МК eeprom_write_default_settings(); // Проверка, заполнен ли EEPROM eeprom_read_settings(); // Чтение настроек из EEPROM screen=1; Power.USB_active=DISABLE; Power.sleep_time=Settings.Sleep_time; Power.Display_active=ENABLE; ADCData.DAC_voltage_raw=0x610; dac_init(); comp_init(); comp_on(); timer9_Config(); // Конфигурируем таймер накачки timer10_Config(); tim2_Config(); sound_activate(); delay_ms(100); sound_deactivate(); //-------------------------------------------------------------------- RTC_Config(); // Конфигурируем часы //-------------------------------------------------------------------- // инициализация дисплея //-------------------------------------------------------------------- delay_ms(50); // подождать установки напряжения display_on(); LcdInit(); LcdClear(); //-------------------------------------------------------------------- adc_init(); delay_ms(100); adc_calibration(); delay_ms(10); //-------------------------------------------------------------------- EXTI8_Config(); #ifdef version_401 EXTI9_Config(); #endif EXTI3_Config(); EXTI4_Config(); EXTI6_Config(); DataUpdate.Need_batt_voltage_update=ENABLE; if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6))hidden_menu=ENABLE; // Открытие сервисных пунктов меню delay_ms(500); // подождать установки напряжения while(1) ///////////////////////////////// { if(DataUpdate.Need_fon_update==ENABLE) geiger_calc_fon(); if(key>0) keys_proccessing(); if(DataUpdate.Need_batt_voltage_update) adc_check_event(); //////////////////////////////////////////////////// if((Power.sleep_time>0)&(!Power.Display_active))sleep_mode(DISABLE); // Если дисплей еще выключен, а счетчик сна уже отсчитывает, поднимаем напряжение и включаем дисплей if(Power.Display_active) { if(Power.sleep_time==0 && !Alarm.Alarm_active) sleep_mode(ENABLE); // Счетчик сна досчитал до нуля, а дисплей еще активен, то выключаем его и понижаем напряжение if(Power.led_sleep_time>0) { GPIO_ResetBits(GPIOC,GPIO_Pin_13);// Включаем подсветку } else { GPIO_SetBits(GPIOC,GPIO_Pin_13);// Выключаем подсветку } if(DataUpdate.Need_display_update==ENABLE) { DataUpdate.Need_display_update=DISABLE; LcdClear_massive(); if (screen==1)main_screen(); if (screen==2)menu_screen(); if (screen==3)stat_screen(); } /////////////////////////////////////////////////////////////////////////////// } #ifdef version_401 if((!Power.USB_active) && (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9))){ usb_activate(0x0); // Если питание USB начало подаваться включаем USB } #endif if(!Power.USB_active) // если USB не активен, можно уходить в сон { if(current_pulse_count<30) // Если счетчик не зашкаливает, то можно уйти в сон { if(!Power.Pump_active && !Power.Sound_active) { PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); // Переходим в сон #ifdef debug Wakeup.total_wakeup++; DataUpdate.Need_display_update=ENABLE; #endif } else { PWR_EnterSleepMode(PWR_Regulator_ON, PWR_SLEEPEntry_WFI); #ifdef debug Wakeup.total_wakeup++; DataUpdate.Need_display_update=ENABLE; #endif } } }else USB_work(); // если USB активен, попробовать передать данные #ifdef debug Wakeup.total_cycle++; DataUpdate.Need_display_update=ENABLE; #endif } /////////////////////////////////////////////////////////////////////////////// }
static inline void adc_init_single(uint32_t adc, uint8_t nb_channels, uint8_t* channel_map) { // Paranoia, must be down for 2+ ADC clock cycles before calibration adc_off(adc); /* Configure ADC */ /* Explicitly setting most registers, reset/default values are correct for most */ /* Set CR1 register. */ /* Clear AWDEN */ adc_disable_analog_watchdog_regular(adc); /* Clear JAWDEN */ adc_disable_analog_watchdog_injected(adc); /* Clear DISCEN */ adc_disable_discontinuous_mode_regular(adc); /* Clear JDISCEN */ adc_disable_discontinuous_mode_injected(adc); /* Clear JAUTO */ adc_disable_automatic_injected_group_conversion(adc); /* Set SCAN */ adc_enable_scan_mode(adc); /* Enable ADC<X> JEOC interrupt (Set JEOCIE) */ adc_enable_eoc_interrupt_injected(adc); /* Clear AWDIE */ adc_disable_awd_interrupt(adc); /* Clear EOCIE */ adc_disable_eoc_interrupt(adc); /* Set CR2 register. */ /* Clear TSVREFE */ #if defined(STM32F1) adc_disable_temperature_sensor(adc); #elif defined(STM32F4) adc_disable_temperature_sensor(); #endif /* Clear EXTTRIG */ adc_disable_external_trigger_regular(adc); /* Clear ALIGN */ adc_set_right_aligned(adc); /* Clear DMA */ adc_disable_dma(adc); /* Clear CONT */ adc_set_single_conversion_mode(adc); //uint8_t x = 0; //for (x = 0; x < nb_channels; x++) { // adc_set_sample_time(adc, channel_map[x], ADC_SAMPLE_TIME); //} adc_set_sample_time_on_all_channels(adc, ADC_SAMPLE_TIME); adc_set_injected_sequence(adc, nb_channels, channel_map); #if USE_AD_TIM4 PRINT_CONFIG_MSG("Info: Using TIM4 for ADC") #if defined(STM32F1) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM4_TRGO); #elif defined(STM32F4) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM4_TRGO, ADC_CR2_JEXTEN_BOTH_EDGES); #endif #elif USE_AD_TIM1 PRINT_CONFIG_MSG("Info: Using TIM1 for ADC") #if defined(STM32F1) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM1_TRGO); #elif defined(STM32F4) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM1_TRGO, ADC_CR2_JEXTEN_BOTH_EDGES); #endif #else PRINT_CONFIG_MSG("Info: Using default TIM2 for ADC") #if defined(STM32F1) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM2_TRGO); #elif defined(STM32F4) adc_enable_external_trigger_injected(adc, ADC_CR2_JEXTSEL_TIM2_TRGO, ADC_CR2_JEXTEN_BOTH_EDGES); #endif #endif /* Enable ADC<X> */ adc_power_on(adc); #if defined(STM32F1) /* Enable ADC<X> reset calibaration register */ adc_reset_calibration(adc); /* Check the end of ADC<X> reset calibration */ while ((ADC_CR2(adc) & ADC_CR2_RSTCAL) != 0); /* Start ADC<X> calibaration */ adc_calibration(adc); /* Check the end of ADC<X> calibration */ while ((ADC_CR2(adc) & ADC_CR2_CAL) != 0); #endif return; } // adc_init_single
void Ad9361RadioInit(int via_fpga, int fd, PRADCONF pRadConfig) { unsigned char Loopback; unsigned char NumAntennas; unsigned char BandNumber; unsigned int rc = 0; unsigned int i; unsigned char val; unsigned char valr; PADRADPROFILE pRadProfile; BandNumber = pRadConfig->Band; NumAntennas = pRadConfig->NumAntennas; Loopback = pRadConfig->TxLoopback; pRadProfile = (PADRADPROFILE)pRadConfig->pRadProfile; // Get revision ID (least significant 3 bits of Product ID register) // // Send first instruction (common to all revs) to enable reads and writes // to the chip // Ad9361WriteReg(via_fpga, fd, 0x3df, 0x01); // // Get the revision ID // val = Ad9361ReadReg(via_fpga, fd, 0x37); val &= 0x07; // Mask out all bits except D2 through D0 printf("AD9361 Revision %u detected\n", val); i = 1; // SKIP 1ST WRITE COMMAND AS IT IS WRITTEN ABOVE NOW while (pRadProfile[i].OpCode != EORP) { switch (pRadProfile[i].OpCode) { case SPIRD: // // Register read operation // val = Ad9361ReadReg(via_fpga, fd, pRadProfile[i].Addr); printf("0x%x=0x%x\n", pRadProfile[i].Addr, val); break; case SPIWR: // // Write operation, search patch table for // alternate value (if any) // And write out current data or patched // data if there is a match in the patch table // val = pRadProfile[i].Data; // TX antenna enable register if (pRadProfile[i].Addr == 2) { // // Antennas mask // Bit 7:1 6:1 // //val = (NumAntennas == 1) ? 0x5E : 0xDE; } // RX antenna enable register if (pRadProfile[i].Addr == 3) { // // Antennas mask // Bit 7:1 6:1 // //val = (NumAntennas == 1) ? 0x5E : 0xDE; } if (pRadProfile[i].Addr == 0x010) { if (pRadConfig->RadioMode == RADMODE_PULSE) val |= 1<<3; // Pulse Mode // RX Frame signal Level mode, bit 3 equals 0 if (NumAntennas == 2) { val |= 1<<2; // 2R2T Timing } } if (pRadProfile[i].Addr == 0x006) { val = (pRadConfig->RadId == 0) ? 0x0F : 0x00; } if (pRadProfile[i].Addr == 0x007) { val = 0x00; } #ifdef CAL_TIA if(pRadProfile[i].Addr >= 0x1DB && pRadProfile[i].Addr <= 0x1DF) { tia_calibration(via_fpga, fd, pRadProfile[i].Addr, &val); } #endif #ifdef CAL_ADC if(pRadProfile[i].Addr >= 0x200 && pRadProfile[i].Addr <= 0x227) { adc_calibration(via_fpga, fd, pRadProfile[i].Addr, &val); } #endif Ad9361WriteReg(via_fpga, fd, pRadProfile[i].Addr, val); break; case DELAY: // // Delay operation: // sleep(5 * pRadProfile[i].Data / 1000); break; case WCALDONE: // // Wait Calibration done operation // sleep(pRadProfile[i].Data / 1000); break; } i++; } // set loopback mode Ad9361SetLoopback(via_fpga, fd, (Loopback == 1) ? 1 : 0); printf("AD9361 driver initialization completed\n"); #ifdef DUMP_AD9361_REGISTERS Ad9361DumpRegs(via_fpga, fd); #endif }
void accel_highg_init() { uint8_t channel_array[16]; gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO0 | GPIO1 | GPIO2); adc_set_dual_mode(ADC_CR1_DUALMOD_RSM); /* ADC1 + ADC2 dual mode */ adc_set_dual_mode(ADC_CR1_DUALMOD_ISM); adc_enable_external_trigger_injected(ADC1, ADC_CR2_JEXTSEL_TIM1_TRGO); adc_enable_external_trigger_injected(ADC3, ADC_CR2_JEXTSEL_TIM1_TRGO); adc_enable_dma(ADC1); adc_enable_dma(ADC3); adc_power_on(ADC1); adc_power_on(ADC2); adc_power_on(ADC3); adc_stab_sleep(); adc_reset_calibration(ADC1); adc_reset_calibration(ADC2); adc_reset_calibration(ADC3); adc_calibration(ADC1); adc_calibration(ADC2); adc_calibration(ADC3); memset(channel_array, 0, sizeof(channel_array)); channel_array[0] = 10; adc_set_injected_sequence(ADC1, 1, channel_array); channel_array[0] = 11; adc_set_injected_sequence(ADC2, 1, channel_array); channel_array[0] = 12; adc_set_injected_sequence(ADC3, 1, channel_array); timer_reset(TIM1); timer_enable_irq(TIM1, TIM_DIER_UIE); timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); /* 500Hz */ timer_set_prescaler(TIM1, 64); timer_set_period(TIM1, 2250); /* Generate TRGO */ timer_set_master_mode(TIM1, TIM_CR2_MMS_UPDATE); dma_set_peripheral_address(DMA1, DMA_CHANNEL5, (uint32_t) &ADC1_DR); dma_set_read_from_memory(DMA1, DMA_CHANNEL5); dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL5); dma_set_peripheral_size(DMA1, DMA_CHANNEL5, DMA_CCR_PSIZE_32BIT); dma_set_memory_size(DMA1, DMA_CHANNEL5, DMA_CCR_MSIZE_32BIT); dma_set_priority(DMA1, DMA_CHANNEL5, DMA_CCR_PL_HIGH); dma_set_peripheral_address(DMA1, DMA_CHANNEL6, (uint32_t) &ADC3_DR); dma_set_read_from_peripheral(DMA1, DMA_CHANNEL6); dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL6); dma_set_peripheral_size(DMA1, DMA_CHANNEL6, DMA_CCR_PSIZE_16BIT); dma_set_memory_size(DMA1, DMA_CHANNEL6, DMA_CCR_MSIZE_16BIT); dma_set_priority(DMA1, DMA_CHANNEL6, DMA_CCR_PL_HIGH); dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL5); dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL6); }
static void setup_stm32f1_peripherals(void) { rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_I2C1EN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); /* GPIO pin for I2C1 SCL, SDA */ /* VESNA v1.0 gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, GPIO6); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, GPIO7); */ /* VESNA v1.1 */ AFIO_MAPR |= AFIO_MAPR_I2C1_REMAP; gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, TDA_PIN_SCL); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, TDA_PIN_SDA); /* GPIO pin for TDA18219 IRQ */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TDA_PIN_IRQ); /* GPIO pin for TDA18219 IF AGC */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TDA_PIN_IF_AGC); /* Set to lowest gain for now */ gpio_clear(GPIOA, TDA_PIN_IF_AGC); /* GPIO pin for AD8307 ENB */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TDA_PIN_ENB); /* ADC pin for AD8307 output */ gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, TDA_PIN_OUT); /* Setup I2C */ i2c_peripheral_disable(I2C1); /* 400 kHz - I2C Fast Mode */ i2c_set_clock_frequency(I2C1, I2C_CR2_FREQ_24MHZ); i2c_set_fast_mode(I2C1); /* 400 kHz */ i2c_set_ccr(I2C1, 0x14); /* 300 ns rise time */ i2c_set_trise(I2C1, 0x08); i2c_peripheral_enable(I2C1); /* Make sure the ADC doesn't run during config. */ adc_off(ADC1); /* We configure everything for one single conversion. */ adc_disable_scan_mode(ADC1); adc_set_single_conversion_mode(ADC1); adc_enable_discontinous_mode_regular(ADC1); adc_disable_external_trigger_regular(ADC1); adc_set_right_aligned(ADC1); adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); adc_on(ADC1); /* Wait for ADC starting up. */ int i; for (i = 0; i < 800000; i++) /* Wait a bit. */ __asm__("nop"); adc_reset_calibration(ADC1); adc_calibration(ADC1); uint8_t channel_array[16]; /* Select the channel we want to convert. */ if(TDA_PIN_OUT == GPIO0) { channel_array[0] = 0; } else if(TDA_PIN_OUT == GPIO2) { channel_array[0] = 2; } adc_set_regular_sequence(ADC1, 1, channel_array); }