Rev 474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 474 | Rev 480 | ||
---|---|---|---|
Line 115... | Line 115... | ||
115 | GPIO_Init(GPIO2, &GPIO_InitStructure); |
115 | GPIO_Init(GPIO2, &GPIO_InitStructure); |
Line 116... | Line 116... | ||
116 | 116 | ||
117 | u8 i; |
117 | u8 i; |
Line 118... | Line 118... | ||
118 | u32 delay; |
118 | u32 delay; |
119 | 119 | ||
- | 120 | #define SCL0_LOW GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_RESET); |
|
- | 121 | #define SCL0_HIGH GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_SET); |
|
- | 122 | #define SDA0_LOW GPIO_WriteBit(GPIO2, GPIO_Pin_1, Bit_RESET); |
|
- | 123 | #define SDA0_HIGH GPIO_WriteBit(GPIO2, GPIO_Pin_1, Bit_SET); |
|
120 | // set SCL high and then SDA to low (start condition) |
124 | |
121 | GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_SET); |
125 | // set SCL high and then SDA to high (stopp condition) |
122 | delay = SetDelay(1); |
126 | SCL0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
123 | while (!CheckDelay(delay)); |
127 | SDA0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
- | 128 | SCL0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
- | 129 | SDA0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
124 | GPIO_WriteBit(GPIO2, GPIO_Pin_1, Bit_RESET); |
130 | |
125 | // toggle SCL at least 10 times from high to low to high |
131 | // 10 * Clock |
126 | for(i = 0; i < 10; i++) |
132 | for(i = 0; i < 10; i++) |
127 | { |
133 | { |
128 | delay = SetDelay(1); |
- | |
129 | while (!CheckDelay(delay)); |
- | |
130 | 134 | SCL0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
131 | GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_RESET); |
135 | // SDA0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
132 | delay = SetDelay(1); |
- | |
133 | while (!CheckDelay(delay)); |
136 | SCL0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
134 | GPIO_WriteBit(GPIO2, GPIO_Pin_0, Bit_SET); |
- | |
135 | } |
- | |
136 | delay = SetDelay(1); |
137 | // SDA0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
137 | while (!CheckDelay(delay)); |
138 | } |
138 | // create stop condition setting SDA HIGH when SCL is HIGH |
- | |
- | 139 | // create stop condition setting SDA HIGH when SCL is HIGH |
|
- | 140 | SCL0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
- | 141 | SDA0_LOW; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
Line 139... | Line 142... | ||
139 | GPIO_WriteBit(GPIO2, GPIO_Pin_1, Bit_SET); |
142 | SCL0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
140 | 143 | SDA0_HIGH; delay = SetDelay(1); while (!CheckDelay(delay)); |
|
141 | 144 | ||
142 | // reconfigure P2.0->I2C0_CLKOUT and P2.1->I2C0_DOUT |
145 | // reconfigure P2.0->I2C0_CLKOUT and P2.1->I2C0_DOUT |