Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Source code under CC0 1.0
- #include <stdint.h>
- #include <stdio.h>
- #define EVER (;;)
- //ADC Registers
- #define ADC1_CR1 (*(volatile uint8_t *)0x5340)
- #define ADC1_CR2 (*(volatile uint8_t *)0x5341)
- #define ADC1_CR3 (*(volatile uint8_t *)0x5342)
- //System Configuration
- #define SYSCFG_RMPCR1 (*(volatile uint8_t *)0x509E)
- #define USART1TR_REMAP1 (1 << 5)
- #define USART1TR_REMAP0 (1 << 4)
- //Clock
- #define CLK_DIVR (*(volatile uint8_t *)0x50C0)
- #define CLK_PCKENR1 (*(volatile uint8_t *)0x50C3)
- #define CLK_PCKENR2 (*(volatile uint8_t *)0x50C4)
- //USART
- #define USART1_SR (*(volatile uint8_t *)0x5230)
- #define USART1_DR (*(volatile uint8_t *)0x5231)
- #define USART1_BRR1 (*(volatile uint8_t *)0x5232)
- #define USART1_BRR2 (*(volatile uint8_t *)0x5233)
- #define USART1_CR2 (*(volatile uint8_t *)0x5235)
- #define USART1_CR3 (*(volatile uint8_t *)0x5236)
- #define USART_CR2_TEN (1 << 3)
- #define USART_CR3_STOP2 (1 << 5)
- #define USART_CR3_STOP1 (1 << 4)
- #define USART_SR_TXE (1 << 7)
- // we need to provide putchar, as it is controller specific
- void putchar(char c)
- {
- while(!(USART1_SR & USART_SR_TXE));
- USART1_DR = c;
- }
- void uart_init(void)
- {
- // Remap USART1 TX to PA2 and RX to PA4
- SYSCFG_RMPCR1 |= USART1TR_REMAP0;
- SYSCFG_RMPCR1 &= ~USART1TR_REMAP1;
- USART1_CR2 = USART_CR2_TEN; // Allow TX and RX
- USART1_CR3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit
- USART1_BRR2 = 0x03; USART1_BRR1 = 0x68; // 9600 baud
- }
- void main(void)
- {
- unsigned long i = 0;
- CLK_DIVR = 0x00; // Set the frequency to 16 MHz
- CLK_PCKENR1 |= 0xFF; //(1 << 5) & (1 << 7); // Enable peripherals UART & ADC
- uart_init();
- printf("Restarted...\r\n");
- for EVER
- {
- ADC1_CR1 = 0x01;
- printf("ADC_CR1: %X\r\n", ADC1_CR1);
- for(i = 0; i < 0xFFFFF; i++); // Sleep
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement