I have been working a couple of days on this one and right now I feel really stuck.
I have 5 MCP23017s on my PCB where 2 of them are strictly used as outputs and 3 strictly as inputs.
I have to be honest and say that in no possible way am I going to use the port expander click library since there is no data, information, or help with the functions and couldn't even compile the example.
I am doing this the old-fashioned way, datasheet on the right, PCB and debugger on the left, and PC in the middle.
As for the "OUTPUT" ICs the debugging took just over a couple of hours and they are working like a charm.
The initialization here:
Code: Select all
buffer[0] = MCP23017_IODIRA; // MCP23017 IODIRA register address
buffer[1] = 0x00; // Set all pins of port A as outputs
I2C2_Start(); // Start I2C communication
I2C2_Write(address, buffer, 2, END_MODE_STOP); // Write to MCP23017 IODIRA and IODIRB registers
buffer[0] = MCP23017_IODIRB; // MCP23017 IODIRB register address
buffer[1] = 0x00; // Set all pins of port B as outputs
I2C2_Start(); // Start I2C communication
I2C2_Write(address, buffer, 2, END_MODE_STOP); // Write to MCP23017 IODIRA and IODIRB registers
Code: Select all
buffer[0] = port;
buffer[1] = datax;
I2C2_Start();
I2C2_Write(address, buffer, 2, END_MODE_STOP);
Does anyone have a sample code for initializing and reading port states of MCP23017 over I2C in MikroC pro for ARM?
The I2C library is not even close to what it was before on older architectures.
I would love to have a simple library with elementary functions such as "S" "SR" "W" "R" etc.
here is just one not-working version of read function for example
Code: Select all
I2C2_Start(); // Start I2C communication
I2C2_Write(0x20, 0x12, 1, END_MODE_RESTART);
I2C2_Read(0x20, dataci, 2, END_MODE_STOP);
Where 0x20 has been replaced with 0x41 to resemble the R/W bit being 1 for reading etc.
Thank you for your help. Best regards,
Nermin
UPDATE:
My Current read function is as follows:
Code: Select all
I2C2_Start(); // Start I2C communication
I2C2_Write(address, 0x12, 1, END_MODE_RESTART);
I2C2_Read(address, bufferc, 2, END_MODE_STOP);
However, if I read from IODRA/B registers eg:
Code: Select all
I2C2_Start(); // Start I2C communication
I2C2_Write(address, 0x00, 1, END_MODE_RESTART);
I2C2_Read(address, bufferc, 2, END_MODE_STOP);
Thanks.