int main(void) { rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); spi_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ dogm128_init(); dogm128_clear(); dogm128_set_cursor(0, 56); dogm128_print_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); dogm128_set_cursor(0, 48); dogm128_print_string("abcdefghijklmnopqrstuvwxyz"); dogm128_set_cursor(0, 40); dogm128_print_string(" !#$%&'()*+,-./0123456789"); dogm128_set_cursor(0, 32); dogm128_print_string(":;<=>?@[\\]^_`{|}~"); dogm128_set_dot(10, 10); dogm128_set_dot(20, 10); dogm128_set_dot(30, 10); dogm128_set_dot(40, 10); dogm128_set_dot(50, 10); dogm128_update_display(); gpio_set(GPIOB, GPIO7); /* LED1 off */ while (1); /* Halt. */ return 0; }
int main(void) { rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); nvic_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN); /* the goal is to let the LED2 glow for a second and then be off for a second */ /* Set timer start value */ TIM_CNT(TIM2) = 1; /* Set timer prescaler. 72MHz/1440 => 50000 counts per second */ TIM_PSC(TIM2) = 1440; /* End timer value. If this value is reached an interrupt is generated */ TIM_ARR(TIM2) = 50000; /* Update interrupt enable */ TIM_DIER(TIM2) |= TIM_DIER_UIE; /* Start timer */ TIM_CR1(TIM2) |= TIM_CR1_CEN; while(1); /* Halt. */ return 0; }
int main(void) { rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ temp32 = 0; /* 72MHz / 8 => 9000000 counts per second */ systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ systick_set_reload(9000); systick_interrupt_enable(); /* start counting */ systick_counter_enable(); while(1); /* Halt. */ 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) { 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) { int i = 0; uint16_t temperature; rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); usart_setup(); i2c_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'); stts75_write_config(I2C2, STTS75_SENSOR0); stts75_write_temp_os(I2C2, STTS75_SENSOR0, 0x1a00); /* 26 degrees */ stts75_write_temp_hyst(I2C2, STTS75_SENSOR0, 0x1a00); temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0); /* Send the temperature as binary over USART1. */ for (i = 15; i >= 0; i--) { if (temperature & (1 << i)) usart_send(USART1, '1'); else usart_send(USART1, '0'); } usart_send(USART1, '\r'); usart_send(USART1, '\n'); gpio_clear(GPIOB, GPIO6); /* LED2 on */ while (1); /* Halt. */ return 0; }
// Setup the main loop int main(void) { // Set the system clock: rcc_clock_setup_in_hse_16mhz_out_72mhz(); systick_init(); // Setup the GPIO for the Indicator LED rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12); // Set the memory in the stack char dyn_on[8] = "\xFF\xFF\xFE\x04\x03\x19\x01\xE0"; char dyn_off[8] = "\xFF\xFF\xFE\x04\x03\x19\x00\xE1"; // Initialize the RS485 communication system // This requires use of DMA1 Channel 4 and USART1 rs485_init( 2000000 ); while(1) { // Init on every loop rs485_init( 2000000 ); // On for half a second, off for half a second gpio_clear(GPIOC, GPIO12); rs485_putstrn( (u32) &dyn_on, 8); _delay_us( 250000 ); // Off... gpio_set(GPIOC, GPIO12); rs485_putstrn( (u32) &dyn_off, 8); _delay_us( 250000 ); } return 0; }
int main(void) { /* Exactly 20 bytes including '0' at the end. We want to transfer 32bit * 5 so it should fit */ char s1[20] = "Hello STM MEM2MEM\r\n"; char s2[20]; rcc_clock_setup_in_hse_16mhz_out_72mhz(); gpio_setup(); usart_setup(); gpio_clear(GPIOB, GPIO7); /* LED1 on */ gpio_set(GPIOB, GPIO6); /* LED2 off */ my_usart_print_string(USART1, "s1 "); my_usart_print_string(USART1, s1); rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_DMA1EN); /* MEM2MEM mode for channel 1. */ dma_enable_mem2mem_mode(DMA1, DMA_CHANNEL1); /* Highest priority. */ dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR1_PL_VERY_HIGH); /* 32Bit wide transfer for source and destination. */ dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR1_MSIZE_32BIT); dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR1_PSIZE_32BIT); /* After each 32Bit we have to increase the addres because we use RAM. */ dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1); dma_enable_peripheral_increment_mode(DMA1, DMA_CHANNEL1); /* We define the source as peripheral. */ dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1); /* We want to transfer string s1. */ dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (u32) &s1); /* Destination should be string s2. */ dma_set_memory_address(DMA1, DMA_CHANNEL1, (u32) &s2); /* Set number of DATA to transfer. Remember that this means not necessary bytes but MSIZE or PSIZE depending from your source device. */ dma_set_number_of_data(DMA1, DMA_CHANNEL1, 5); /* Start DMA transfer. */ dma_enable_channel(DMA1, DMA_CHANNEL1); /* TODO: write a function to get the interrupt flags. */ while(!(DMA_ISR(DMA1) & 0x0000001)) { } dma_disable_channel(DMA1, DMA_CHANNEL1); /* String s1 should now already be transferred to s2. */ my_usart_print_string(USART1, "s2 "); my_usart_print_string(USART1, s2); gpio_clear(GPIOB, GPIO6); /* LED2 on */ while(1); /* Halt. */ return 0; }