diff --git a/Hello_World/Makefile b/Hello_World/Makefile index 2efde347e427b18e360dec4db235ddf8537c010b..f399063a90405f0bbb0606392e282c0175276eec 100644 --- a/Hello_World/Makefile +++ b/Hello_World/Makefile @@ -90,6 +90,8 @@ PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE #PROJ_CFLAGS+=--specs=nano.specs #PROJ_LDFLAGS+=--specs=nano.specs +PROJ_CFLAGS+=-std=c99 + # Point this variable to a startup file to override the default file #STARTUPFILE=start.S diff --git a/Hello_World/main.c b/Hello_World/main.c index 74ffc81c4da71d02cf0a52f16006a7a2a58c5191..7e5a7b6af9463e6509adc582e18463503754b5ec 100644 --- a/Hello_World/main.c +++ b/Hello_World/main.c @@ -47,13 +47,22 @@ #include "led.h" #include "board.h" #include "tmr_utils.h" +#include "i2c.h" /***** Definitions *****/ +#define I2C_DEVICE MXC_I2C0_BUS0 + /***** Globals *****/ /***** Functions *****/ - +#if 0 +void I2C0_IRQHandler(void) +{ + I2C_Handler(I2C_DEVICE); + return; +} +#endif // ***************************************************************************** int main(void) { @@ -61,6 +70,23 @@ int main(void) printf("Hello World!\n"); + //Setup the I2CM + I2C_Shutdown(I2C_DEVICE); + I2C_Init(I2C_DEVICE, I2C_FAST_MODE, NULL); + #if 0 + NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests + #endif + + uint8_t dummy[1] = {0}; + // "7-bit addresses 0b0000xxx and 0b1111xxx are reserved" + for (int addr = 0x8; addr < 0x78; ++addr) { + // A 0 byte write does not seem to work so always send a single byte. + int res = I2C_MasterWrite(I2C_DEVICE, addr << 1, dummy, 1, 0); + if(res == 1) { + printf("Found (7 bit) address 0x%02x\n", addr); + } + } + while (1) { LED_On(0); TMR_Delay(MXC_TMR0, MSEC(500), 0);