Use more defines when using main clock or master clock

This commit is contained in:
Philippe Teuwen 2019-08-06 13:40:08 +02:00
commit 8b3159c83d
6 changed files with 11 additions and 8 deletions

View file

@ -229,9 +229,9 @@ void usart_init(uint32_t baudrate, uint8_t parity) {
// OVER = 1, -yes we are oversampling
// baudrate == selected clock/8/CD --> this is ours
//
uint32_t brgr = 48000000 / (usart_baudrate << 3);
uint32_t brgr = MCK / (usart_baudrate << 3);
// doing fp = round((mck / (usart_baudrate << 3) - brgr) * 8) with integers:
uint32_t fp = ((16 * 48000000 / (usart_baudrate << 3) - 16 * brgr) + 1) / 2;
uint32_t fp = ((16 * MCK / (usart_baudrate << 3) - 16 * brgr) + 1) / 2;
pUS1->US_BRGR = (fp << 16) | brgr;

View file

@ -450,7 +450,7 @@ AT91S_CDC_LINE_CODING line = { // purely informative, actual values don't matter
// WARNING: timer can't measure more than 1.39s (21.3uS * 0xffff)
static void SpinDelay(int ms) {
int us = ms * 1000;
int ticks = (48 * us + 512) >> 10;
int ticks = ((MCK / 1000000) * us + 512) >> 10;
// Borrow a PWM unit for my real-time clock
AT91C_BASE_PWMC->PWMC_ENA = PWM_CHANNEL(0);