Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "inc/stm8s.h"
- #include "inc/stm8s_gpio.h"
- #include <stdlib.h>
- #include <stdio.h>
- const uint16_t clk_start = CLK_BaseAddress;
- const char *clk_regs_names[] =
- {
- "ICKR =",
- "ECKR =",
- "RESERVED =",
- "CMSR =",
- "SWR =",
- "SWCR =",
- "CKDIVR =",
- "PCKENR1 =",
- "CSSR =",
- "CCOR =",
- "PCKENR2 =",
- "RESERVED1 =",
- "HSITRIMR =",
- "SWIMCCR ="
- };
- uint8_t clk_regs_values[sizeof(clk_regs_names)];
- unsigned char out_str[32];
- void uart_tx_string(unsigned char *str);
- //================================ UART ======================================//
- void UART1_init(void)
- {
- // Baudrate 9600 for F_CPU = 16 MHz
- UART1->BRR2 = 0x03;
- UART1->BRR1 = 0x68;
- UART1->CR1 = 0x00;
- UART1->CR2 = /*UART1_CR2_REN | UART1_CR2_RIEN |*/ UART1_CR2_TEN;
- }
- // Отправка байта
- inline void uart_tx_byte(uint8_t data)
- {
- while(!(UART1->SR & UART1_SR_TXE));
- UART1->DR = data;
- }
- // For debugging feature
- void uart_tx_string(unsigned char *str)
- {
- while(*str != 0) {uart_tx_byte(*str++);};
- }
- //============================ UART END ======================================//
- void main(void)
- {
- // UART TX pin
- GPIOD->ODR = 0x00;
- GPIOD->DDR |= GPIO_PIN_5;
- GPIOD->CR1 |= GPIO_PIN_5;
- GPIOD->CR2 |= GPIO_PIN_5;
- for (uint8_t i = 0; i < sizeof(clk_regs_values); i++)
- {
- clk_regs_values[i] = *((uint8_t *)(clk_start +i));
- }
- // Disable clock prescaler. F_CPU = 16 MHz
- CLK->CKDIVR = 0x00;
- UART1_init();
- uart_tx_byte('\n');
- for (uint8_t i = 0; i < sizeof(clk_regs_names)/sizeof(clk_regs_names[0]); i++)
- {
- sprintf(out_str, "%-s 0x%02X\n", clk_regs_names[i], clk_regs_values[i]);
- uart_tx_string(out_str);
- }
- uart_tx_string("Initialization complete.\n");
- while(1)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement