int main(void) { clock_setup(); gpio_setup(); usart_setup(); i2c_setup(); /*uint8_t data[1]={(0x4 << ACC_CTRL_REG1_A_ODR_SHIFT) | ACC_CTRL_REG1_A_XEN};*/ uint8_t data[1]={0x97}; write_i2c(I2C1, I2C_ACC_ADDR, ACC_CTRL_REG1_A, 1, data); data[0]=0x08; write_i2c(I2C1, I2C_ACC_ADDR, ACC_CTRL_REG4_A, 1, data); uint16_t acc_x; while (1) { read_i2c(I2C1, I2C_ACC_ADDR, ACC_STATUS, 1, data); /*my_usart_print_int(USART2, data[0]);*/ read_i2c(I2C1, I2C_ACC_ADDR, ACC_OUT_X_L_A, 1, data); acc_x=data[0]; read_i2c(I2C1, I2C_ACC_ADDR, ACC_OUT_X_H_A, 1, data); acc_x|=(data[0] << 8); my_usart_print_int(USART2, (int16_t) acc_x); //int i; //for (i = 0; i < 800000; i++) /* Wait a bit. */ // __asm__("nop"); } return 0; }
int main(void) { rcc_clock_setup_in_hse_12mhz_out_72mhz(); gpio_setup(); usart_setup(); timer_setup(); irq_setup(); adc_setup(); gpio_set(GPIOA, GPIO8); /* LED1 off */ gpio_set(GPIOC, GPIO15); /* LED5 off */ /* Send a message on USART1. */ usart_send_blocking(USART2, 's'); usart_send_blocking(USART2, 't'); usart_send_blocking(USART2, 'm'); usart_send_blocking(USART2, '\r'); usart_send_blocking(USART2, '\n'); /* Moved the channel selection and sequence init to adc_setup() */ /* Continously convert and poll the temperature ADC. */ while (1) { /* * Since sampling is triggered by the timer and copying the values * out of the data registers is handled by the interrupt routine, * we just need to print the values and toggle the LED. It may be useful * to buffer the adc values in some cases. */ my_usart_print_int(USART2, temperature); usart_send_blocking(USART2, ' '); my_usart_print_int(USART2, v_refint); usart_send_blocking(USART2, ' '); my_usart_print_int(USART2, lisam_adc1); usart_send_blocking(USART2, ' '); my_usart_print_int(USART2, lisam_adc2); usart_send_blocking(USART2, '\r'); gpio_toggle(GPIOA, GPIO8); /* LED2 on */ } return 0; }
int main(void) { uint8_t channel_array[16]; uint16_t temperature = 0; rcc_clock_setup_in_hse_12mhz_out_72mhz(); gpio_setup(); usart_setup(); timer_setup(); adc_setup(); gpio_set(GPIOA, GPIO8); /* LED1 on */ gpio_set(GPIOC, GPIO15); /* LED2 on */ /* Send a message on USART1. */ usart_send_blocking(USART2, 's'); usart_send_blocking(USART2, 't'); usart_send_blocking(USART2, 'm'); usart_send_blocking(USART2, '\r'); usart_send_blocking(USART2, '\n'); /* Select the channel we want to convert. 16=temperature_sensor. */ channel_array[0] = 16; /* Set the injected sequence here, with number of channels */ adc_set_injected_sequence(ADC1, 1, channel_array); /* Continously convert and poll the temperature ADC. */ while (1) { /* * Since the injected sampling is triggered by the timer, it gets * updated automatically, we just need to periodically read out the value. * It would be better to check if the JEOC bit is set, and clear it following * so that you do not read the same value twice, especially for a slower * sampling rate. */ temperature = adc_read_injected(ADC1,1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits) /* * That's actually not the real temperature - you have to compute it * as described in the datasheet. */ my_usart_print_int(USART2, temperature); gpio_toggle(GPIOA, GPIO8); /* LED2 on */ } return 0; }
int main(void) { u8 channel_array[16]; u16 temperature; rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); usart_setup(); adc_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ /* Send a message on USART1. */ usart_send(USART1, 's'); usart_send(USART1, 't'); usart_send(USART1, 'm'); usart_send(USART1, '\r'); usart_send(USART1, '\n'); /* Select the channel we want to convert. 16=temperature_sensor. */ channel_array[0] = 16; adc_set_regular_sequence(ADC1, 1, channel_array); /* * If the ADC_CR2_ON bit is already set -> setting it another time * starts the conversion. */ adc_on(ADC1); /* Wait for end of conversion. */ while (!(ADC_SR(ADC1) & ADC_SR_EOC)); temperature = ADC_DR(ADC1); /* * That's actually not the real temperature - you have to compute it * as described in the datasheet. */ my_usart_print_int(USART1, temperature); gpio_clear(GPIOB, GPIO6); /* LED2 on */ while(1); /* Halt. */ return 0; }
int main(void) { u8 channel_array[16]; rcc_clock_setup_in_hse_12mhz_out_72mhz(); gpio_setup(); usart_setup(); timer_setup(); irq_setup(); adc_setup(); gpio_set(GPIOA, GPIO8); /* LED1 on */ gpio_set(GPIOC, GPIO15); /* LED2 on */ /* Send a message on USART1. */ usart_send_blocking(USART2, 's'); usart_send_blocking(USART2, 't'); usart_send_blocking(USART2, 'm'); usart_send_blocking(USART2, '\r'); usart_send_blocking(USART2, '\n'); /* Select the channel we want to convert. 16=temperature_sensor. */ channel_array[0] = 16; /* Set the injected sequence here, with number of channels */ adc_set_injected_sequence(ADC1, 1, channel_array); /* Continously convert and poll the temperature ADC. */ while (1) { /* * Since sampling is triggered by the timer and copying the value * out of the data register is handled by the interrupt routine, * we just need to print the value and toggle the LED. It may be useful * to buffer the adc values in some cases. */ /* * That's actually not the real temperature - you have to compute it * as described in the datasheet. */ my_usart_print_int(USART2, temperature); gpio_toggle(GPIOA, GPIO8); /* LED2 on */ } return 0; }
int main(void) { uint8_t channel_array[16]; uint16_t temperature; rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); usart_setup(); adc_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ /* Send a message on USART1. */ usart_send(USART1, 's'); usart_send(USART1, 't'); usart_send(USART1, 'm'); usart_send(USART1, '\r'); usart_send(USART1, '\n'); /* Select the channel we want to convert. 16=temperature_sensor. */ channel_array[0] = 16; adc_set_regular_sequence(ADC1, 1, channel_array); /* * Start the conversion directly (not trigger mode). */ adc_start_conversion_direct(ADC1); /* Wait for end of conversion. */ while (!(ADC_SR(ADC1) & ADC_SR_EOC)); temperature = ADC_DR(ADC1); /* * That's actually not the real temperature - you have to compute it * as described in the datasheet. */ my_usart_print_int(USART1, temperature); gpio_clear(GPIOB, GPIO6); /* LED2 on */ while(1); /* Halt. */ return 0; }
int main(void) { uint16_t temp; clock_setup(); gpio_setup(); adc_setup(); usart_setup(); while (1) { adc_start_conversion_regular(ADC1); while (!(adc_eoc(ADC1))); temp=adc_read_regular(ADC1); gpio_port_write(GPIOE, temp << 4); my_usart_print_int(USART2, temp); } return 0; }
int main(void) { uint16_t temp; adc_setup(); usart_setup(); while (1) { adc_start_conversion_regular(ADC1); while (!(adc_eoc(ADC1))); temp = adc_read_regular(ADC1); my_usart_print_int(USART1, temp); int i; for (i = 0; i < 800000; i++) { /* Wait a bit. */ __asm__("nop"); } } return 0; }
int main(void) { uint8_t temp; int16_t gyr_x; clock_setup(); gpio_setup(); usart_setup(); spi_setup(); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_CTRL_REG1); spi_read8(SPI1); spi_send8(SPI1, GYR_CTRL_REG1_PD | GYR_CTRL_REG1_XEN | GYR_CTRL_REG1_YEN | GYR_CTRL_REG1_ZEN | (3 << GYR_CTRL_REG1_BW_SHIFT)); spi_read8(SPI1); gpio_set(GPIOE, GPIO3); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_CTRL_REG4); spi_read8(SPI1); spi_send8(SPI1, (1 << GYR_CTRL_REG4_FS_SHIFT)); spi_read8(SPI1); gpio_set(GPIOE, GPIO3); while (1) { gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_WHO_AM_I | GYR_RNW); spi_read8(SPI1); spi_send8(SPI1, 0); temp=spi_read8(SPI1); my_usart_print_int(USART2, (temp)); gpio_set(GPIOE, GPIO3); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_STATUS_REG | GYR_RNW); spi_read8(SPI1); spi_send8(SPI1, 0); temp=spi_read8(SPI1); my_usart_print_int(USART2, (temp)); gpio_set(GPIOE, GPIO3); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_OUT_TEMP | GYR_RNW); spi_read8(SPI1); spi_send8(SPI1, 0); temp=spi_read8(SPI1); my_usart_print_int(USART2, (temp)); gpio_set(GPIOE, GPIO3); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_OUT_X_L | GYR_RNW); spi_read8(SPI1); spi_send8(SPI1, 0); gyr_x=spi_read8(SPI1); gpio_set(GPIOE, GPIO3); gpio_clear(GPIOE, GPIO3); spi_send8(SPI1, GYR_OUT_X_H | GYR_RNW); spi_read8(SPI1); spi_send8(SPI1, 0); gyr_x|=spi_read8(SPI1) << 8; my_usart_print_int(USART2, (gyr_x)); gpio_set(GPIOE, GPIO3); int i; for (i = 0; i < 80000; i++) /* Wait a bit. */ __asm__("nop"); } return 0; }