Hi all,
For an LPC2132 application I required a third I2C bus and implemented this using bit banging of GPIO pins. A logical 0 is implemented by driving the GPIO pin to low, a logical 1 is implemented by setting the GPIO to input and having an external resistor pulling the signal high. This works perfectly in real hardware.
As I generally simulate my software with Keil uVision, I have the problem of simulating the external pullup resistors. The simulation function below, shows errors when I try to raise the PORT0 to high. The error message is something like "Trying to write to a GPIO that is configured as output".
Does anybody have a different solution to simulate pullups? What is wrong with my pullup implementation?
Thanks.
----
define unsigned long io0dir_old[32]; func void pullup( int port, int bit_num ) { unsigned long io0dir; unsigned long mask; mask = (1<<bit_num); io0dir = _RDWORD( &IO0DIR ); printf( "IO0DIR event: IO0DIR = %08x\n", io0dir ); if( (io0dir & mask) != (io0dir_old[bit_num] & mask) ) { printf( "io0dir(%d) changed to %d\n", bit_num, (io0dir&mask)>>bit_num ); if( (io0dir & mask) == 0 ) { // if direction==input //swatch( 0.0000001 ); if( (PORT0 & mask) == 0 ) { PORT0 |= mask; // ...scl=1 printf( "Pullup activated on PORT%d.%d\n", port, bit_num ); } } } io0dir_old[bit_num] = io0dir; } signal void pullup_port0_18(void) { int bit_num; bit_num = 18; io0dir_old[bit_num] = _RDWORD( &IO0DIR ); while (1) { wwatch( &IO0DIR ); pullup( 0, bit_num ); } } pullup_port0_18();