I am new to KSDK and Kinetis processors, but I have I2C working except that the Processor Expert code is not properly setting the Open Drain Enable bit for the SDA and SCL pins. When I try to set the bit in my code, an interrupt occurs. This is in a "bare metal" system. I'm trying to set the bit like this:
volatile uint32_t *portc10 = (void *)0x4004b028;
*portc10 |= (1 << 5);
The interrupt occurs when portc10 is dereferenced.
I have no idea why this is happening unless there is memory protection being turned on by something, but that should be the case in a bare metal (standalone) platform. If so, how do I turn it off so I can set this bit?
Thanks,
Aric.
I learned that if I hacked the code above into the pin_mux.c code that is generated by Processor Expert, the setting of the Open Drain Enable works.
So further debugging showed that the culprit is this line in the Common_Init() funciton of Cpu.c in the generated code:
SIM_SCGC5 &= (uint32_t)~(uint32_t)(SIM_SCGC5_PORTC_MASK);
Which apparently turns the clock off to the GPIO Port C controller. So accesses to registers in that space must hang causing a watchdog reset or a bus exception.
In my own code, I am able to turn that clock back on and then set the Open Drain Enable as needed to get I2C to work properly.
Aric.