104,7 → 104,7 |
// and clock out at least 9 SCL pulses, then generate a stop |
// condition and then leave the clock line high. |
|
// configure P2.2->I2C0_CLKOUT and P2.3->I2C0_DOUT to normal port operation |
// configure P2.0->I2C0_CLKOUT and P2.1->I2C0_DOUT to normal port operation |
GPIO_StructInit(&GPIO_InitStructure); |
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; |
115,6 → 115,7 |
|
u8 i; |
u32 delay; |
|
// set SCL high and then SDA to low (start condition) |
GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_SET); |
delay = SetDelay(1); |
137,7 → 138,7 |
GPIO_WriteBit(GPIO2, GPIO_Pin_1, Bit_SET); |
|
|
// reconfigure P2.2->I2C0_CLKOUT and P2.3->I2C0_DOUT |
// reconfigure P2.0->I2C0_CLKOUT and P2.1->I2C0_DOUT |
GPIO_StructInit(&GPIO_InitStructure); |
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; |
169,7 → 170,7 |
|
VIC_Config(I2C0_ITLine, VIC_IRQ , PRIORITY_I2C0); |
|
I2C0_Timeout = SetDelay(10*I2C0_Timeout); |
I2C0_Timeout = SetDelay(10*I2C1_TIMEOUT); |
I2C_GenerateSTOP(I2C0, ENABLE); |
I2C0_State = I2C_STATE_IDLE; |
|
214,7 → 215,7 |
I2C0_TxBufferSize = 0; |
I2C0_RxBufferSize = 0; |
|
I2C0_Timeout = SetDelay(10*I2C0_Timeout); |
I2C0_Timeout = SetDelay(10*I2C0_TIMEOUT); |
|
UART1_PutString("ok"); |
} |
224,7 → 225,6 |
{ |
static u8 Rx_Idx = 0, Tx_Idx = 0; |
u16 status; |
u8 text[20]; |
|
|
|
246,9 → 246,6 |
} |
else |
{ // depending on current i2c state |
|
sprintf(text, "%02X ", status); |
UART1_PutString(text); |
switch(status) |
{ |
// the start condition was initiated on the bus |
387,7 → 384,7 |
} |
} |
//IDISABLE; // do not enable IRQ nesting for I2C!!!! |
VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
} |
|
// ---------------------------------------------------------------------------------------- |
444,7 → 441,7 |
I2C0_SlaveAddress = SlaveAddr; |
I2C0_pRxHandler = pRxHandler; |
// test on busy flag and clear it |
I2C_CheckEvent( I2C0, I2C_FLAG_BUSY ); |
I2C_ClearFlag(I2C0, I2C_FLAG_BUSY); |
// enable I2C IRQ |
VIC_ITCmd(I2C0_ITLine, ENABLE); |
// initiate start condition on the bus |