Does the Kernel of the NetDCU6 support I2C.
Is there any example available?
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- Driver for I2C
- --------------
- Installation under
- [HKLM\Drivers\BuiltIn\I2C1]
- [HKLM\Drivers\BuiltIn\I2C2]
- [HKLM\Drivers\BuiltIn\I2C3]
- ...
- Entry Value Description
- --------------------------------------------------------------------
- Prefix: "I2C" I2Cx:
- Dll: "I2C.DLL" Driver DLL
- Order: Dword:101 Load sequence
- Index: Dword:1 For I2C1
- Dword:2 For I2C2
- ...
- FriendlyName: "I2C driver for NetDCU" Description
- ClockFreq: Dword:5000 in Hz, Default: 50000
- AckRetries: Dword:0 Number of Retries to get ACK
- Default: 0 (no retry)
- PinSCL: Dword:0x00000200 Pin config for Clock line
- Default: 0x00000200 = Pin13
- PinSDA: Dword:0x00000100 Pin config for Data line
- Default: 0x00000100 = Pin15
- The pin configurations use the mappings for the Digital I/O ports:
- Pin on J5 Value for registry
- -------------------------------
- 2 0x00000080
- 3 0x00000040
- 4 0x00000020
- 5 0x00000010
- 6 0x00000008
- 7 0x00000004
- 8 0x00000002
- 9 0x00000001
- 10 0x00000800
- 11 0x00000400
- 13 0x00000200
- 15 0x00000100
- The AckRetries parameter specifies, how many clock cycles the NetDCU
- will wait until the ACK from the device is assumed missing. Usually
- the device should send the acknowledge immediately after the 8 data
- bits, so 0 is OK in most cases.
- If an I2C parameter is not specified, the driver will use the default
- values. Please make sure that I2C1, I2C2, ... use different pin
- configurations.
- Example:
- Device I2C1: on default pins, 60kHz
- Device I2C2: on Pins 2..3, 10kHz
- [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\I2C1]
- "Prefix" = "I2C"
- "Dll" = "i2c.dll"
- "Index" = dword:1
- "Order" = dword:101
- "FriendlyName" = "I2C driver for NetDCU"
- "ClockFreq" = dword:60000
- [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\I2C2]
- "Prefix" = "I2C"
- "Dll" = "i2c.dll"
- "Index" = dword:2
- "Order" = dword:102
- "FriendlyName" = "I2C driver for NetDCU"
- "ClockFreq" = dword:10000
- "PinSCL" = dword:0x00000080
- "PinSDA" = dword:0x00000040
- The I2C driver uses an IOCTL to transfer the data to/from the device.
- The file
- i2cio.h
- defines the appropriate structures and IOCTL codes.
- typedef struct tagI2CData
- {
- unsigned char chDeviceAddr; /* Address of I2C device (7 bit!) */
- unsigned char chFlags; /* Bit 0: Don't use RESTART */
- unsigned short wWriteLen; /* Number of bytes to write */
- unsigned short wReadLen; /* Number of bytes to read */
- unsigned char *pchWriteBuf; /* Buffer with data to send */
- unsigned char *pchReadBuf; /* Buffer for received data */
- } I2C_DATA, *PI2C_DATA;
- Usually you will set up the I2C_DATA structure and call the IOCTL with
- command IOCTL_I2C_TRANSFER. This issues the follwing process:
- 1. A START condition is generated on the bus.
- 2. The device address is issued together with WRITE access.
- 3. The data with length wWriteLen, stored at pchWriteBuf, is sent to
- the device.
- 4. A RESTART condition is generated on the bus.
- 5. The device address is issued together with READ access.
- 6. Data with length wReadLen is read from the device and stored at
- pchReadBuf. For the last byte received, the NetDCU does not issue
- an Acknowledge to stop the read transfer.
- 7. A STOP condition is generated on the bus and the bus is released.
- This allows for example to send a command byte (like a register number
- within the device) first and then read data from the device in one go.
- This is usally required for SMBus devices.
- If you want the driver to not use the RESTART condition when changing
- from WRITE to READ, then set the flag I2C_NORESTART in chFlags. Then
- the driver uses a normal STOP-START sequence.
- If you want to have a write-only transfer, then either use command
- IOCTL_I2C_WRITE or set wReadLen to 0 or pchReadBuf to NULL. If you
- want to have a read-only transfer, then either use command
- IOCTL_I2C_READ or set wWriteLen to 0 or pchWriteBuf to NULL.
- Driver usage example
- --------------------
- This example uses the 16 bit I/O device PCA9555 on the default pin
- connection (like on I2C1 above). We configure address 0x20 on the
- device, which means A0=0, A1=0, A2=0.
- Connection list:
- PCA9555-Pin NetDCU pin on J5
- ------------------------------------------
- 1 INT -
- 2 A1 16 GND
- 3 A2 16 GND
- 4-11 IO Port 0 -
- 12 Vss 16 GND
- 13-20 IO Port 1 -
- 21 A0 16 GND
- 22 SCL 13 SCL
- 23 SDA 15 SDA
- 24 Vdd 26 VCC (3.3V)
- Program code:
- /*****************************************************************************/
- /*** File: pca9555.cpp ***/
- /*** Author: Hartmut Keller ***/
- /*** Created: 14.04.2005 ***/
- /*** Modified: 14.04.2005 18:46:42 (HK) ***/
- /*** ***/
- /*** Description: ***/
- /*** Example for I2C driver on NetDCU, using 16 Bit I/O chip PCA9555. ***/
- /*****************************************************************************/
- #include "i2cio.h" /* IOCTL_I2C_* */
- /* Access type for device as a file */
- #define I2CSHARE 0 /*FILE_SHARE_READ*/ /* Share mode */
- #define I2CACCESS (GENERIC_READ | GENERIC_WRITE) /* Access mode */
- /* Registers of the PCA9555 */
- #define PCA9555_IN0 0 /* Input port 0 */
- #define PCA9555_IN1 1 /* Input port 1 */
- #define PCA9555_OUT0 2 /* Output port 0 */
- #define PCA9555_OUT1 3 /* Output port 0 */
- #define PCA9555_INV0 4 /* Polarity inversion port 0 */
- #define PCA9555_INV1 5 /* Polarity inversion port 0 */
- #define PCA9555_CNF0 6 /* Configuration port 0 */
- #define PCA9555_CNF1 7 /* Configuration port 0 */
- /* Function to set an 8 bit register of the PCA9555 */
- void SetReg8(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg, BYTE chValue)
- {
- I2C_DATA id;
- BYTE setbuf[2];
- setbuf[0] = chReg;
- setbuf[1] = chValue;
- id.chDeviceAddr = chDevAddr;
- id.wWriteLen = 2;
- id.pchWriteBuf = setbuf;
- DeviceIoControl(hOpenContext, IOCTL_I2C_WRITE, (LPBYTE)&id, sizeof(id),
- NULL, 0, NULL, NULL);
- }
- /* Function to set a pair of 8 bit registers of the PCA9555 */
- void SetReg16(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg, WORD wValue)
- {
- I2C_DATA id;
- BYTE setbuf[3];
- setbuf[0] = chReg;
- setbuf[1] = (BYTE)(wValue >> 8);
- setbuf[2] = (BYTE)wValue;
- id.chDeviceAddr = chDevAddr;
- id.wWriteLen = 3;
- id.pchWriteBuf = setbuf;
- DeviceIoControl(hOpenContext, IOCTL_I2C_WRITE, (LPBYTE)&id, sizeof(id),
- NULL, 0, NULL, NULL);
- }
- /* Function to read an 8 bit register of the PCA9555 */
- BYTE GetReg8(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg)
- {
- I2C_DATA id;
- BYTE setbuf[1];
- BYTE getbuf[1];
- setbuf[0] = chReg;
- id.chDeviceAddr = chDevAddr;
- id.wWriteLen = 1;
- id.pchWriteBuf = setbuf;
- id.wReadLen = 1;
- id.pchReadBuf = getbuf;
- DeviceIoControl(hOpenContext, IOCTL_I2C_TRANSFER, (LPBYTE)&id, sizeof(id),
- NULL, 0, NULL, NULL);
- return getbuf[0];
- }
- /* Function to read a pair of 8 bit registers of the PCA9555 */
- WORD GetReg16(I2CHANDLE hOpenContext, BYTE chDevAddr, BYTE chReg)
- {
- I2C_DATA id;
- BYTE setbuf[1];
- BYTE getbuf[2];
- setbuf[0] = chReg;
- id.chDeviceAddr = chDevAddr;
- id.wWriteLen = 1;
- id.pchWriteBuf = setbuf;
- id.wReadLen = 2;
- id.pchReadBuf = getbuf;
- DeviceIoControl(hOpenContext, IOCTL_I2C_TRANSFER, (LPBYTE)&id, sizeof(id),
- NULL, 0, NULL, NULL);
- return (WORD)(getbuf[0] << 8) | (WORD)getbuf[1];
- }
- /* Sample program scanning the I2C bus for the device and then setting and
- reading some registers of it */
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine, int nCmdShow)
- {
- /* Simulate device.exe behaviour */
- I2CHANDLE hOpenContext;
- BYTE chDevAddr;
- WORD wValue;
- I2C_SCAN_DATA buffer;
- int i;
- hOpenContext = CreateFile(TEXT("I2C1:"), I2CACCESS, I2CSHARE, NULL,
- OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0);
- chDevAddr = 0;
- /* Scan I2C bus for devices */
- I2C_IOCTL(hOpenContext, IOCTL_I2C_SCAN, NULL, 0, buffer, 128, NULL);
- for (i=0; i<128; i++)
- {
- if (buffer[i])
- {
- printf("Found device on address 0x%02x.\n", i << 1);
- if ((i >= 0x20) && (i < 0x28))
- chDevAddr = (BYTE)i; /* Found PCA9555 */
- }
- }
- if (chDevAddr)
- {
- /* Set ports to input */
- SetReg16(hOpenContext, chDevAddr, PCA9555_CNF0, 0xFFFF);
- /* Read ports */
- wValue = GetReg16(hOpenContext, chDevAddr, PCA9555_IN0);
- /* Set port 1 to output */
- SetReg8(hOpenContext, chDevAddr, PCA9555_CNF1, 0x00);
- /* Set value on port 1 */
- SetReg8(hOpenContext, chDevAddr, PCA9555_OUT1, 0x55);
- /* Read ports */
- wValue = GetReg16(hOpenContext, chDevAddr, PCA9555_IN0);
- /* Read ports using 8 bit access */
- wValue = (WORD)(GetReg8(hOpenContext, chDevAddr, PCA9555_IN0)<<8)
- | (WORD)GetReg8(hOpenContext, chDevAddr, PCA9555_IN1);
- }
- CloseHandle(hOpenContext);
- return 0;
- }
-
Hello again,
can you send me an email, then i will send you the driver and header file.