from: https://eroro.tistory.com/601
Remote 16-bit I/O expander for I2C-bus 테스트 프로그램
PIN 7에서 PIN 10번으로 넘어가는 부분을 PIN 8번으로 작성하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/************************** (C) COPYRIGHT 2023 ***************** * File Name : * Author : * Version : Ver 0.1 * Date : 2023/03/15 * Description : * * Revision History * Date Version Name Description 2023/03/15 0.1 Oanny Proto. *******************************************************************************/ #ifndef __USR_I2C_H #define __USR_I2C_H #include "stm32f10x.h" #include "usr_system.h" /* ADDR : 0100 A2 A1 A0 RW */ #define PCF8575_ADDRESS 0x40 /* DATA DIR => 0100 A2 A1 A0 RW (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) */ #define I2C_Speed 100000 #define I2C_1 1 #define I2C_2 2 /* BASE : 0100 A2 A1 A0 RW (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) READ : 0100 A2 A1 A0 0 (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) WRITE : 0100 A2 A1 A0 1 (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) */ #define PCF8575_Pin_0 ((uint8_t)0x0001) /*!< Pin 0 selected */ #define PCF8575_Pin_1 ((uint8_t)0x0002) /*!< Pin 1 selected */ #define PCF8575_Pin_2 ((uint8_t)0x0004) /*!< Pin 2 selected */ #define PCF8575_Pin_3 ((uint8_t)0x0008) /*!< Pin 3 selected */ #define PCF8575_Pin_4 ((uint8_t)0x0010) /*!< Pin 4 selected */ #define PCF8575_Pin_5 ((uint8_t)0x0020) /*!< Pin 5 selected */ #define PCF8575_Pin_6 ((uint8_t)0x0040) /*!< Pin 6 selected */ #define PCF8575_Pin_7 ((uint8_t)0x0080) /*!< Pin 7 selected */ #define PCF8575_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */ #define PCF8575_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */ #define PCF8575_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */ #define PCF8575_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */ #define PCF8575_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */ #define PCF8575_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */ #define PCF8575_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */ #define PCF8575_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */ #define PCF8575_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */ void I2C_Config(uint8_t i2c, uint32_t speed); void I2C2_ByteWrite(uint16_t a_DeviceAddr, uint8_t* pBuffer); void I2C2_BufferRead(uint16_t a_DeviceAddr, uint8_t* pBuffer, uint16_t NumByteToRead); void PCF8575_Demo(void); #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
/************************** (C) COPYRIGHT 2023 ***************** * File Name : * Author : * Version : Ver 0.1 * Date : 2023/03/15 * Description : * * Revision History * Date Version Name Description 2023/03/15 0.1 Oanny Proto. *******************************************************************************/ #include <stdarg.h> #include <stdio.h> #include <string.h> #include "usr_i2c.h" #include "usr_uart.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ #if 0 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) { while(BufferLength--) { if(*pBuffer1 != *pBuffer2) { return FAILED; } pBuffer1++; pBuffer2++; } return PASSED; } #endif /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : - I2C2 - PB10 EN PB11 FREQ I2C_Config(I2C_1, I2C_Speed); *******************************************************************************/ void I2C_Config(uint8_t i2c, uint32_t speed) { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; if(i2c == I2C_1){ /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure I2C1 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); /* I2C configuration */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = PCF8575_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = speed; /* I2C Peripheral Enable */ I2C_Cmd(I2C1, ENABLE); /* Apply I2C configuration after enabling it */ I2C_Init(I2C1, &I2C_InitStructure); } else if(i2c == I2C_2){ /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure I2C2 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); /* I2C configuration */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = PCF8575_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = speed; /* I2C Peripheral Enable */ I2C_Cmd(I2C2, ENABLE); /* Apply I2C configuration after enabling it */ I2C_Init(I2C2, &I2C_InitStructure); } } #define I2C_TIMEOUT 0x100000 /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ void I2C2_ByteWrite(uint16_t a_DeviceAddr, uint8_t* pBuffer) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* Send STRAT condition */ I2C_GenerateSTART(I2C2, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for write */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Transmitter); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, pBuffer[0]); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, pBuffer[1]); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STOP condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ void I2C2_ByteRead(uint16_t a_DeviceAddr, uint8_t* pBuffer, uint16_t NumByteToRead) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* While the bus is busy */ while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STRAT condition a second time */ I2C_GenerateSTART(I2C2, ENABLE); I2C_Timeout = I2C_TIMEOUT; /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for read */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Receiver); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* While there is data to be read */ while(NumByteToRead) { if(NumByteToRead == 1){ /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C2, DISABLE); /* Send STOP Condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /* Test on EV7 and clear it */ if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED)){ /* Read a byte from the EEPROM */ *pBuffer = I2C_ReceiveData(I2C2); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Decrement the read bytes counter */ NumByteToRead--; } } /* Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ void I2C2_HalfWordWrite(uint16_t a_DeviceAddr, uint16_t pBuffer) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* Send STRAT condition */ I2C_GenerateSTART(I2C2, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for write */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Transmitter); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, (uint8_t)(pBuffer & 0x00FF)); // DEBUGPRINT("W1 %X\r\n", (uint8_t)(pBuffer & 0x00FF)); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, (uint8_t)((pBuffer & 0xFF00) >> 8)); // DEBUGPRINT("W2 %X\r\n", (uint8_t)((pBuffer & 0xFF00) >> 8)); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STOP condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ uint16_t I2C2_HalfWordRead(uint16_t a_DeviceAddr) { uint32_t I2C_Timeout = I2C_TIMEOUT; uint8_t I2C_Buffer[2], Buf_Poi = 0, NumByteToRead; /* While the bus is busy */ while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STRAT condition a second time */ I2C_GenerateSTART(I2C2, ENABLE); I2C_Timeout = I2C_TIMEOUT; /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for read */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Receiver); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } NumByteToRead = 2; /* While there is data to be read */ while(NumByteToRead) { if(NumByteToRead == 1){ /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C2, DISABLE); /* Send STOP Condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /* Test on EV7 and clear it */ if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED)){ /* Read a byte from the EEPROM */ I2C_Buffer[Buf_Poi] = I2C_ReceiveData(I2C2); /* Point to the next location where the byte read will be saved */ Buf_Poi++; /* Decrement the read bytes counter */ NumByteToRead--; } } /* Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(I2C2, ENABLE); return I2C_Buffer[0] | (I2C_Buffer[1] << 8); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ uint8_t PCF8575_ReadInputDataBit(uint16_t GPIO_Pin) { uint8_t bitstatus = 0x00; if ((I2C2_HalfWordRead(PCF8575_ADDRESS) & GPIO_Pin) != (uint32_t)Bit_RESET){ bitstatus = (uint8_t)Bit_SET; } else{ bitstatus = (uint8_t)Bit_RESET; } return bitstatus; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ void PCF8575_Demo(void) { I2C_Config(I2C_2, I2C_Speed); while(1){ #if 0 uint8_t i = 0; uint8_t I2C_Buffer[2] = {0, }; if(i == 0){ I2C_Buffer[0] = 0; I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 1){ I2C_Buffer[0] = (uint8_t)GPIO_Pin_0; I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 2){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 3){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 4){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 5){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 6){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 7){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 8){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 9){ I2C_Buffer[1] = (uint8_t)GPIO_Pin_0; I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 10){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 11){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 12){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 13){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 14){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 15){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 16){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_ByteWrite(PCF8575_ADDRESS, I2C_Buffer); delay_ms(500); I2C_Buffer[0] = 0; I2C_Buffer[1] = 0; I2C2_ByteRead(PCF8575_ADDRESS, I2C_Buffer, 2); DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); i++; if(i > 16) i=0; #else uint16_t I2C_Buffer; I2C_Buffer = PCF8575_Pin_0 | PCF8575_Pin_8 | PCF8575_Pin_9; GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_HalfWordWrite(PCF8575_ADDRESS, I2C_Buffer); I2C_Buffer = 0; DEBUGPRINT("R1 %X\r\n", I2C2_HalfWordRead(PCF8575_ADDRESS)); if(PCF8575_ReadInputDataBit(PCF8575_Pin_0) == Bit_SET){ DEBUGPRINT("P0 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_1) == Bit_SET){ DEBUGPRINT("P1 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_2) == Bit_SET){ DEBUGPRINT("P2 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_3) == Bit_SET){ DEBUGPRINT("P3 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_4) == Bit_SET){ DEBUGPRINT("P4 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_5) == Bit_SET){ DEBUGPRINT("P5 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_6) == Bit_SET){ DEBUGPRINT("P6 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_7) == Bit_SET){ DEBUGPRINT("P7 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_8) == Bit_SET){ DEBUGPRINT("P8 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_9) == Bit_SET){ DEBUGPRINT("P9 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_10) == Bit_SET){ DEBUGPRINT("P10 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_11) == Bit_SET){ DEBUGPRINT("P11 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_12) == Bit_SET){ DEBUGPRINT("P12 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_13) == Bit_SET){ DEBUGPRINT("P13 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_14) == Bit_SET){ DEBUGPRINT("P14 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_15) == Bit_SET){ DEBUGPRINT("P15 Set\r\n"); } delay_ms(500); I2C_Buffer = 0; GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_HalfWordWrite(PCF8575_ADDRESS, I2C_Buffer); I2C_Buffer = 0; // DEBUGPRINT("R2 %X\r\n", I2C2_HalfWordRead(PCF8575_ADDRESS)); delay_ms(500); #endif } } |