From 31c1e30b67038f9bd44d39c7a5efd487e9cc6db3 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Sun, 30 Aug 2020 05:20:18 +0200 Subject: [PATCH] working prototype --- newcode/main.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- newcode/makefile | 4 ++-- newcode/yaMBSiavr.c | 30 ++++++++++++++++++++++++------ newcode/yaMBSiavr.h | 2 +- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/newcode/main.c b/newcode/main.c index e34c808..0230b57 100644 --- a/newcode/main.c +++ b/newcode/main.c @@ -1,11 +1,12 @@ #include #include -#include "uart.h" #include +#include "yaMBSiavr.h" + +uint16_t inputStatus[9]; void init_clk(void) { - // ========= System Clock configuration ========= // Set to external 16Mhz crystal, using the PLL at *2 // set it to be a 12-16Mhz crystal with a slow start-up time. @@ -28,18 +29,47 @@ void init_clk(void) // ============================================== } +void init_timer_100us(){ + TCC0.CTRLA |= TC_CLKSEL_DIV256_gc; + TCC0.PER = 13; // ==> 9615us + TCC0.INTCTRLA |= TC_OVFINTLVL_MED_gc; +} + +void modbusGet(void) { + if (modbusGetBusState() & (1<> 8) | (bscale << USART_BSCALE0_bp); + + USARTD0.CTRLB = USART_TXEN_bm | USART_RXEN_bm; + //Interrupt enable (levels) - //Physical type - //Busstate + USARTD0.CTRLA |= USART_RXCINTLVL_HI_gc; + USARTD0.CTRLA |= USART_TXCINTLVL_HI_gc; + + PORTD_OUTSET = PIN3_bm; + PORTD_DIRSET = PIN3_bm; + PORTD_OUTCLR = PIN2_bm; + PORTD_DIRCLR = PIN2_bm; + + //TODO Physical type 485 + + BusState=(1<