]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
ADCuC: float output on USB w/ sprintf()
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 13:21:08 +0000 (15:21 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 13:21:08 +0000 (15:21 +0200)
atmega32u4/adcuc/Makefile
atmega32u4/adcuc/main.c

index df1b1fcfae4a0f9301740b0a6e4a8077500cb8c7..3062ad7ea97eacb9dea7b4d164b3c51164b18a38 100644 (file)
@@ -37,7 +37,7 @@ CINCS =
 
 CDEBUG = -g$(DEBUG)
 CWARN = -Wall -Wstrict-prototypes 
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -Wl,--relax
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -Wl,--relax -Wl,-u,vfprintf -lprintf_flt -lm
 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING)
 
index 491804b49cf3b0feeede3aa9de3a621bee66b2a0..039a67e7a3b69353374da605e8db15d0e03a4228 100644 (file)
@@ -5,6 +5,7 @@
 #include <avr/io.h>
 #include <avr/eeprom.h>
 #include <string.h>
+#include <stdio.h>
 #include <usb_serial.h>
 
 #define FIRMWARE_VERSION 0x011
@@ -63,7 +64,7 @@ volatile uint16_t time = 0;
 
 uint8_t rxcnt = 0;
 uint8_t rxbuf[7];
-uint8_t txbuf[16];
+uint8_t txbuf[32];
 
 uint8_t conversion_active = 0;
 uint8_t channel = 0;
@@ -81,22 +82,13 @@ uint8_t hex_to_int(uint8_t h) { //assumes valid number
                 return h-0x61+10;
   }
 
-void send_answer_hex(uint8_t chan, uint16_t v) {
-  txbuf[0]='A';//ADC
-  txbuf[1]=nib_to_hex(chan,0);
-  txbuf[2]='-';//temperature or modi
-  txbuf[3]=nib_to_hex(v,3);
-  txbuf[4]=nib_to_hex(v,2);
-  txbuf[5]=nib_to_hex(v,1);
-  txbuf[6]=nib_to_hex(v,0);
-  txbuf[7]='\n';
-  txbuf[8] = 0;
-  usb_serial_write(txbuf,8);
+void send_answer(uint8_t chan, float v) {
+  int nbytes = sprintf(txbuf, "A%1d %.3f\n", chan, v);
+  usb_serial_write(txbuf, nbytes);
   usb_serial_flush_output();
   }
 
 
-
 ISR(TIMER0_OVF_vect) {
   time++;
   asm volatile("wdr");
@@ -119,8 +111,10 @@ void getdata(uint8_t buf) {
   }
 
 void original_value(uint8_t channel, uint8_t get_value_1, uint8_t get_value_2) {
-  uint16_t result = (get_value_1 << 8) | get_value_2;
-  send_answer_hex(channel+1,result);
+  uint16_t val = (get_value_1 << 8) | get_value_2;
+  float result = val;
+  result = result / 8.0 / 1000.;
+  send_answer(channel+1, result);
   }
 
 void update_eeprom(void) {