I2C, NetDcu6

      Hello,

      for NetDCU6 we support I2C via GPIO.
      Attached a sample. I will check if dll is free and keep you informed.

      C Source Code

      1. Driver for I2C
      2. --------------
      3. Installation under
      4. [HKLM\Drivers\BuiltIn\I2C1]
      5. [HKLM\Drivers\BuiltIn\I2C2]
      6. [HKLM\Drivers\BuiltIn\I2C3]
      7. ...
      8. Entry Value Description
      9. --------------------------------------------------------------------
      10. Prefix: "I2C" I2Cx:
      11. Dll: "I2C.DLL" Driver DLL
      12. Order: Dword:101 Load sequence
      13. Index: Dword:1 For I2C1
      14. Dword:2 For I2C2
      15. ...
      16. FriendlyName: "I2C driver for NetDCU" Description
      17. ClockFreq: Dword:5000 in Hz, Default: 50000
      18. AckRetries: Dword:0 Number of Retries to get ACK
      19. Default: 0 (no retry)
      20. PinSCL: Dword:0x00000200 Pin config for Clock line
      21. Default: 0x00000200 = Pin13
      22. PinSDA: Dword:0x00000100 Pin config for Data line
      23. Default: 0x00000100 = Pin15
      24. The pin configurations use the mappings for the Digital I/O ports:
      25. Pin on J5 Value for registry
      26. -------------------------------
      27. 2 0x00000080
      28. 3 0x00000040
      29. 4 0x00000020
      30. 5 0x00000010
      31. 6 0x00000008
      32. 7 0x00000004
      33. 8 0x00000002
      34. 9 0x00000001
      35. 10 0x00000800
      36. 11 0x00000400
      37. 13 0x00000200
      38. 15 0x00000100
      39. The AckRetries parameter specifies, how many clock cycles the NetDCU
      40. will wait until the ACK from the device is assumed missing. Usually
      41. the device should send the acknowledge immediately after the 8 data
      42. bits, so 0 is OK in most cases.
      43. If an I2C parameter is not specified, the driver will use the default
      44. values. Please make sure that I2C1, I2C2, ... use different pin
      45. configurations.
      46. Example:
      47. Device I2C1: on default pins, 60kHz
      48. Device I2C2: on Pins 2..3, 10kHz
      49. [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\I2C1]
      50. "Prefix" = "I2C"
      51. "Dll" = "i2c.dll"
      52. "Index" = dword:1
      53. "Order" = dword:101
      54. "FriendlyName" = "I2C driver for NetDCU"
      55. "ClockFreq" = dword:60000
      56. [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\I2C2]
      57. "Prefix" = "I2C"
      58. "Dll" = "i2c.dll"
      59. "Index" = dword:2
      60. "Order" = dword:102
      61. "FriendlyName" = "I2C driver for NetDCU"
      62. "ClockFreq" = dword:10000
      63. "PinSCL" = dword:0x00000080
      64. "PinSDA" = dword:0x00000040
      65. The I2C driver uses an IOCTL to transfer the data to/from the device.
      66. The file
      67. i2cio.h
      68. defines the appropriate structures and IOCTL codes.
      69. typedef struct tagI2CData
      70. {
      71. unsigned char chDeviceAddr; /* Address of I2C device (7 bit!) */
      72. unsigned char chFlags; /* Bit 0: Don't use RESTART */
      73. unsigned short wWriteLen; /* Number of bytes to write */
      74. unsigned short wReadLen; /* Number of bytes to read */
      75. unsigned char *pchWriteBuf; /* Buffer with data to send */
      76. unsigned char *pchReadBuf; /* Buffer for received data */
      77. } I2C_DATA, *PI2C_DATA;
      78. Usually you will set up the I2C_DATA structure and call the IOCTL with
      79. command IOCTL_I2C_TRANSFER. This issues the follwing process:
      80. 1. A START condition is generated on the bus.
      81. 2. The device address is issued together with WRITE access.
      82. 3. The data with length wWriteLen, stored at pchWriteBuf, is sent to
      83. the device.
      84. 4. A RESTART condition is generated on the bus.
      85. 5. The device address is issued together with READ access.
      86. 6. Data with length wReadLen is read from the device and stored at
      87. pchReadBuf. For the last byte received, the NetDCU does not issue
      88. an Acknowledge to stop the read transfer.
      89. 7. A STOP condition is generated on the bus and the bus is released.
      90. This allows for example to send a command byte (like a register number
      91. within the device) first and then read data from the device in one go.
      92. This is usally required for SMBus devices.
      93. If you want the driver to not use the RESTART condition when changing
      94. from WRITE to READ, then set the flag I2C_NORESTART in chFlags. Then
      95. the driver uses a normal STOP-START sequence.
      96. If you want to have a write-only transfer, then either use command
      97. IOCTL_I2C_WRITE or set wReadLen to 0 or pchReadBuf to NULL. If you
      98. want to have a read-only transfer, then either use command
      99. IOCTL_I2C_READ or set wWriteLen to 0 or pchWriteBuf to NULL.
      100. Driver usage example
      101. --------------------
      102. This example uses the 16 bit I/O device PCA9555 on the default pin
      103. connection (like on I2C1 above). We configure address 0x20 on the
      104. device, which means A0=0, A1=0, A2=0.
      105. Connection list:
      106. PCA9555-Pin NetDCU pin on J5
      107. ------------------------------------------
      108. 1 INT -
      109. 2 A1 16 GND
      110. 3 A2 16 GND
      111. 4-11 IO Port 0 -
      112. 12 Vss 16 GND
      113. 13-20 IO Port 1 -
      114. 21 A0 16 GND
      115. 22 SCL 13 SCL
      116. 23 SDA 15 SDA
      117. 24 Vdd 26 VCC (3.3V)
      118. Program code:
      119. /*****************************************************************************/
      120. /*** File: pca9555.cpp ***/
      121. /*** Author: Hartmut Keller ***/
      122. /*** Created: 14.04.2005 ***/
      123. /*** Modified: 14.04.2005 18:46:42 (HK) ***/
      124. /*** ***/
      125. /*** Description: ***/
      126. /*** Example for I2C driver on NetDCU, using 16 Bit I/O chip PCA9555. ***/
      127. /*****************************************************************************/
      128. #include "i2cio.h" /* IOCTL_I2C_* */
      129. /* Access type for device as a file */
      130. #define I2CSHARE 0 /*FILE_SHARE_READ*/ /* Share mode */
      131. #define I2CACCESS (GENERIC_READ | GENERIC_WRITE) /* Access mode */
      132. /* Registers of the PCA9555 */
      133. #define PCA9555_IN0 0 /* Input port 0 */
      134. #define PCA9555_IN1 1 /* Input port 1 */
      135. #define PCA9555_OUT0 2 /* Output port 0 */
      136. #define PCA9555_OUT1 3 /* Output port 0 */
      137. #define PCA9555_INV0 4 /* Polarity inversion port 0 */
      138. #define PCA9555_INV1 5 /* Polarity inversion port 0 */
      139. #define PCA9555_CNF0 6 /* Configuration port 0 */
      140. #define PCA9555_CNF1 7 /* Configuration port 0 */
      141. /* Function to set an 8 bit register of the PCA9555 */
      142. void SetReg8(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg, BYTE chValue)
      143. {
      144. I2C_DATA id;
      145. BYTE setbuf[2];
      146. setbuf[0] = chReg;
      147. setbuf[1] = chValue;
      148. id.chDeviceAddr = chDevAddr;
      149. id.wWriteLen = 2;
      150. id.pchWriteBuf = setbuf;
      151. DeviceIoControl(hOpenContext, IOCTL_I2C_WRITE, (LPBYTE)&id, sizeof(id),
      152. NULL, 0, NULL, NULL);
      153. }
      154. /* Function to set a pair of 8 bit registers of the PCA9555 */
      155. void SetReg16(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg, WORD wValue)
      156. {
      157. I2C_DATA id;
      158. BYTE setbuf[3];
      159. setbuf[0] = chReg;
      160. setbuf[1] = (BYTE)(wValue >> 8);
      161. setbuf[2] = (BYTE)wValue;
      162. id.chDeviceAddr = chDevAddr;
      163. id.wWriteLen = 3;
      164. id.pchWriteBuf = setbuf;
      165. DeviceIoControl(hOpenContext, IOCTL_I2C_WRITE, (LPBYTE)&id, sizeof(id),
      166. NULL, 0, NULL, NULL);
      167. }
      168. /* Function to read an 8 bit register of the PCA9555 */
      169. BYTE GetReg8(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg)
      170. {
      171. I2C_DATA id;
      172. BYTE setbuf[1];
      173. BYTE getbuf[1];
      174. setbuf[0] = chReg;
      175. id.chDeviceAddr = chDevAddr;
      176. id.wWriteLen = 1;
      177. id.pchWriteBuf = setbuf;
      178. id.wReadLen = 1;
      179. id.pchReadBuf = getbuf;
      180. DeviceIoControl(hOpenContext, IOCTL_I2C_TRANSFER, (LPBYTE)&id, sizeof(id),
      181. NULL, 0, NULL, NULL);
      182. return getbuf[0];
      183. }
      184. /* Function to read a pair of 8 bit registers of the PCA9555 */
      185. WORD GetReg16(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg)
      186. {
      187. I2C_DATA id;
      188. BYTE setbuf[1];
      189. BYTE getbuf[2];
      190. setbuf[0] = chReg;
      191. id.chDeviceAddr = chDevAddr;
      192. id.wWriteLen = 1;
      193. id.pchWriteBuf = setbuf;
      194. id.wReadLen = 2;
      195. id.pchReadBuf = getbuf;
      196. DeviceIoControl(hOpenContext, IOCTL_I2C_TRANSFER, (LPBYTE)&id, sizeof(id),
      197. NULL, 0, NULL, NULL);
      198. return (WORD)(getbuf[0] << 8) | (WORD)getbuf[1];
      199. }
      200. /* Sample program scanning the I2C bus for the device and then setting and
      201. reading some registers of it */
      202. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
      203. LPTSTR lpCmdLine, int nCmdShow)
      204. {
      205. /* Simulate device.exe behaviour */
      206. I2CHANDLE hOpenContext;
      207. BYTE chDevAddr;
      208. WORD wValue;
      209. I2C_SCAN_DATA buffer;
      210. int i;
      211. hOpenContext = CreateFile(TEXT("I2C1:"), I2CACCESS, I2CSHARE, NULL,
      212. OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0);
      213. chDevAddr = 0;
      214. /* Scan I2C bus for devices */
      215. I2C_IOCTL(hOpenContext, IOCTL_I2C_SCAN, NULL, 0, buffer, 128, NULL);
      216. for (i=0; i<128; i++)
      217. {
      218. if (buffer[i])
      219. {
      220. printf("Found device on address 0x%02x.\n", i << 1);
      221. if ((i >= 0x20) && (i < 0x28))
      222. chDevAddr = (BYTE)i; /* Found PCA9555 */
      223. }
      224. }
      225. if (chDevAddr)
      226. {
      227. /* Set ports to input */
      228. SetReg16(hOpenContext, chDevAddr, PCA9555_CNF0, 0xFFFF);
      229. /* Read ports */
      230. wValue = GetReg16(hOpenContext, chDevAddr, PCA9555_IN0);
      231. /* Set port 1 to output */
      232. SetReg8(hOpenContext, chDevAddr, PCA9555_CNF1, 0x00);
      233. /* Set value on port 1 */
      234. SetReg8(hOpenContext, chDevAddr, PCA9555_OUT1, 0x55);
      235. /* Read ports */
      236. wValue = GetReg16(hOpenContext, chDevAddr, PCA9555_IN0);
      237. /* Read ports using 8 bit access */
      238. wValue = (WORD)(GetReg8(hOpenContext, chDevAddr, PCA9555_IN0)<<8)
      239. | (WORD)GetReg8(hOpenContext, chDevAddr, PCA9555_IN1);
      240. }
      241. CloseHandle(hOpenContext);
      242. return 0;
      243. }

      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.
      Hello again,

      can you send me an email, then i will send you the driver and header file.
      F&S Elektronik Systeme GmbH
      As this is an international forum, please try to post in English.
      Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.