diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index 3a40ee85aebe9447f9c143067e9c7e6b6e35aed0..0a26752f1884dd5139d9217a8aa2c9cb34253bab 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -25,6 +25,7 @@ int8_t command_handler(char command){ break; case 'G': //Gain - start gain, autogain on/off, (min gain, max gain), low/high switch thresholds //scanf("%1u%1u%7li%7li",&g_gain,&autogain_enable,&overcurrent_threshold,&undercurrent_threshold); + scanf("1u",&g_gain); pot_set_gain(); break; case 'L': //LSV - start, stop, slope diff --git a/DSTAT-temp/src/max5443.c b/DSTAT-temp/src/max5443.c index e9755662f75a6d08e8a5c4f31f5e7a7b2778b4fc..b59609bba2368a9c4675e866f2ddf9c10761a53e 100644 --- a/DSTAT-temp/src/max5443.c +++ b/DSTAT-temp/src/max5443.c @@ -7,6 +7,9 @@ #include +//static uint16_t dac_samples[DMA_BUFFER_SIZE / 2]; +static void dma_init(void); + struct usart_spi_device spi_device_conf_c = { .id = IOPORT_CREATE_PIN(PORTC, 4) }; @@ -19,8 +22,38 @@ void max5443_init_pins(void){ void max5443_init_module(void){ usart_spi_init(&USARTC1); usart_spi_setup_device(&USARTC1, &spi_device_conf_c, SPI_MODE_0, 24000000UL, 0); + + dma_init(); } - + +static void dma_init(void){ + struct dma_channel_config dmach_conf; + memset(&dmach_conf, 0, sizeof(dmach_conf)); + + dma_channel_set_burst_length(&dmach_conf, DMA_CH_BURSTLEN_1BYTE_gc); + dma_channel_set_transfer_count(&dmach_conf, 2); + + dma_channel_set_src_reload_mode(&dmach_conf,DMA_CH_SRCRELOAD_BURST_gc); + dma_channel_set_dest_reload_mode(&dmach_conf,DMA_CH_DESTRELOAD_BURST_gc); + + dma_channel_set_src_dir_mode(&dmach_conf, DMA_CH_SRCDIR_INC_gc); + dma_channel_set_dest_dir_mode(&dmach_conf, DMA_CH_DESTDIR_FIXED_gc); + + dma_channel_set_source_address(&dmach_conf,(uint16_t)(uintptr_t)&TCC1_CNT); + dma_channel_set_destination_address(&dmach_conf,(uint16_t)(uintptr_t)&USARTC1_DATA); + + dma_channel_set_trigger_source(&dmach_conf, DMA_CH_TRIGSRC_TCC0_OVF_gc); + dma_channel_set_single_shot(&dmach_conf); + + dma_enable(); + + //dma_set_callback(DMA_CHANNEL, dma_transfer_done); + //dma_channel_set_interrupt_level(&dmach_conf, DMA_INT_LVL_LO); + + dma_channel_write_config(DMA_CHANNEL, &dmach_conf); + //dma_channel_enable(DMA_CHANNEL); +} + void max5443_set_voltage1(uint16_t dacindex){ static union{ uint8_t ui8[2]; diff --git a/DSTAT-temp/src/max5443.h b/DSTAT-temp/src/max5443.h index 1fae84254f023a2f803babfae055bcaf0ca7bcc1..d09cc9a5400378233da487c77348229c4b4c754e 100644 --- a/DSTAT-temp/src/max5443.h +++ b/DSTAT-temp/src/max5443.h @@ -15,10 +15,15 @@ #include #include #include +#include + +#define DMA_CHANNEL 0 +#define DMA_BUFFER_SIZE 1024 void max5443_init_pins(void); void max5443_init_module(void); void max5443_set_voltage1(uint16_t dacindex); + //void max5443_set_voltage_8bit(uint8_t dacindex); #endif /* MAX5443_H_ */ \ No newline at end of file diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index de22cfb5a14cfe399b34f1d32b2db5d7746053ae..53ebcc89ab96a78c2ff62d1cb91d8009f03925cb 100644 Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ