From 67044cca5b463772491d0712d0ce07a8f897a476 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 9 Apr 2012 00:10:43 -0700 Subject: [PATCH] altos: Test I2C code on discovery board. Signed-off-by: Keith Packard --- src/stm-demo/Makefile | 4 +++- src/stm-demo/ao_demo.c | 21 +++++++++++++++++++++ src/stm-demo/ao_pins.h | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile index 26c81a82..2f156ea4 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -8,6 +8,7 @@ include ../stm/Makefile.defs INC = \ ao.h \ ao_arch.h \ + ao_arch_funcs.h \ ao_pins.h \ ao_product.h @@ -30,7 +31,8 @@ ALTOS_SRC = \ ao_mutex.c \ ao_dma_stm.c \ ao_spi_stm.c \ - ao_adc_stm.c + ao_adc_stm.c \ + ao_i2c_stm.c PRODUCT=StmDemo-v0.0 PRODUCT_DEF=-DSTM_DEMO diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index ea4dadfa..879f7f75 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -111,7 +111,26 @@ ao_spi_read(void) { } } +static void +ao_i2c_write(void) { + unsigned char data[] = { 0x55, 0xaa, 0xff, 0x00 }; + int i; + for (i = 0; i < 10; i++) { + ao_i2c_get(0); + if (ao_i2c_start(0, 0x55)) + ao_i2c_send(data, 4, 0); + else { + printf ("i2c start failed\n"); + ao_i2c_put(0); + break; + } + ao_i2c_put(0); + printf("."); + flush(); + ao_delay(100); + } +} static void ao_temp (void) @@ -133,6 +152,7 @@ __code struct ao_cmds ao_demo_cmds[] = { { ao_dma_test, "D\0DMA test" }, { ao_spi_write, "W\0SPI write" }, { ao_spi_read, "R\0SPI read" }, + { ao_i2c_write, "i\0I2C write" }, { ao_temp, "t\0Show temp" }, { 0, NULL } }; @@ -149,6 +169,7 @@ main(void) // ao_lcd_stm_init(); // ao_lcd_font_init(); ao_spi_init(); + ao_i2c_init(); ao_timer_set_adc_interval(100); diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h index 42f4123d..9fd1175d 100644 --- a/src/stm-demo/ao_pins.h +++ b/src/stm-demo/ao_pins.h @@ -138,5 +138,11 @@ struct ao_adc { #define AO_ADC_SQ2 AO_ADC_TEMP #define AO_ADC_SQ3 AO_ADC_VREF +#define HAS_I2C_1 1 +#define I2C_1_PB6_PB7 0 +#define I2C_1_PB8_PB9 1 + +#define HAS_I2C_2 0 +#define I2C_2_PB10_PB11 0 #endif /* _AO_PINS_H_ */ -- 2.30.2