Exemplo n.º 1
0
Arquivo: periph.c Projeto: mrugala/pm
void initADC()
{
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    GPIO_InitTypeDef gpioStructure;

    gpioStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_5 ;
    gpioStructure.GPIO_Mode = GPIO_Mode_OUT;
    gpioStructure.GPIO_OType = GPIO_OType_PP;
    gpioStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
    gpioStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &gpioStructure);

    gpioStructure.GPIO_Pin = GPIO_Pin_1;
    gpioStructure.GPIO_Mode = GPIO_Mode_OUT;
    gpioStructure.GPIO_OType = GPIO_OType_PP;
    gpioStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
    gpioStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &gpioStructure);

	TM_ADC_InitADC(ADC1);
/*	TM_ADC_InitADC(ADC2);
	TM_ADC_InitADC(ADC3);*/
	TM_ADC_Init(ADC1, TM_ADC_Channel_1);
	TM_ADC_Init(ADC1, TM_ADC_Channel_3);
	TM_ADC_Init(ADC1, TM_ADC_Channel_5);
	TM_ADC_Init(ADC1, TM_ADC_Channel_7);
}
Exemplo n.º 2
0
void TM_ADC_Init(ADC_TypeDef* ADCx, TM_ADC_Channel_t channel) {
	TM_ADC_Channel_t ch = (TM_ADC_Channel_t) channel;
	if (ch == TM_ADC_Channel_0) {
		TM_ADC_INT_Channel_0_Init(ADCx);
	} else if (ch == TM_ADC_Channel_1) {
		TM_ADC_INT_Channel_1_Init(ADCx);
	} else if (ch == TM_ADC_Channel_2) {
		TM_ADC_INT_Channel_2_Init(ADCx);
	} else if (ch == TM_ADC_Channel_3) {
		TM_ADC_INT_Channel_3_Init(ADCx);
	} else if (ch == TM_ADC_Channel_4) {
		TM_ADC_INT_Channel_4_Init(ADCx);
	} else if (ch == TM_ADC_Channel_5) {
		TM_ADC_INT_Channel_5_Init(ADCx);
	} else if (ch == TM_ADC_Channel_6) {
		TM_ADC_INT_Channel_6_Init(ADCx);
	} else if (ch == TM_ADC_Channel_7) {
		TM_ADC_INT_Channel_7_Init(ADCx);
	} else if (ch == TM_ADC_Channel_8) {
		TM_ADC_INT_Channel_8_Init(ADCx);
	} else if (ch == TM_ADC_Channel_9) {
		TM_ADC_INT_Channel_9_Init(ADCx);
	} else if (ch == TM_ADC_Channel_10) {
		TM_ADC_INT_Channel_10_Init(ADCx);
	} else if (ch == TM_ADC_Channel_11) {
		TM_ADC_INT_Channel_11_Init(ADCx);
	} else if (ch == TM_ADC_Channel_12) {
		TM_ADC_INT_Channel_12_Init(ADCx);
	} else if (ch == TM_ADC_Channel_13) {
		TM_ADC_INT_Channel_13_Init(ADCx);
	} else if (ch == TM_ADC_Channel_14) {
		TM_ADC_INT_Channel_14_Init(ADCx);
	} else if (ch == TM_ADC_Channel_15) {
		TM_ADC_INT_Channel_15_Init(ADCx);
	}
	
	/* Init ADC */
	TM_ADC_InitADC(ADCx);
}
Exemplo n.º 3
0
void test_adc()
{
	 char str[150];
	/* Initialize Delay library */
	    TM_DELAY_Init();

	    /* Initialize USART1, 115200 baud, TX: PB6 */
	    //TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);


	    /* Initialize ADC1 on channel 0, this is pin PA0 */
	    //TM_ADC_Init(ADC1, ADC_Channel_0);

	    /* Initialize ADC1 on channel 3, this is pin PA3 */
	    //TM_ADC_Init(ADC1, ADC_Channel_3);

	    /* Initialize ADC1 */
	    TM_ADC_InitADC(ADC1);

	    /* Enable vbat channel */
	    TM_ADC_EnableVbat();


	    while (1) {
	        /* Read & format data */
	        sprintf(str, "----------------------------\nVbat voltage: %d mV\n", TM_ADC_ReadVbat(ADC1));

	        printf("----------------------------\nVbat voltage: %d mV\n", TM_ADC_ReadVbat(ADC1));

	        /* Put to USART */
	        //TM_USART_Puts(USART1, str);

	        /* Little delay */
	        Delayms(1000);
	    }
}