November 23, 2024, 04:46:15 AM

PIC-WEB & I2C

Started by Bart95, February 21, 2013, 08:57:21 AM

Previous topic - Next topic

Bart95

Hi,
I recently decided to use my PIC-WEB rev C (on my shelves for a while) for adding web functionalities to my own PIC development board. My plan is just to use I2C protocol from UEXT for communication exchange between boards.
As a first step, I tried to check the pic web I2C signals without any external cable
1) I upgraded PIC-WEB to 5.42
2) I connected my Digital analyzer to UEXT connector
3) I used the "I2C demo" for a test "out of the box"

My expectation was to see I2C signals on UEXT pins, but it's not the case. SCL & SDA stay "high".
Using demo hex code or new build do not change result.
I am missing or doing something wrong. So here is my dummy question : Do I need to change the default demo C code or pic web hardware jumper for this quick test ?
Any advice ? 

LubOlimex

Hello Bart95,

The default demo of PIC-WEB (the one that is in the device on shipping has no I2C demo). A demo that features I2C control via web page is featured in this package: https://www.olimex.com/Products/PIC/Development/PIC-WEB/resources/PIC_WEB_5_42.zip. Please follow the instructions in "Read Me.txt". The idea is that you can write commands via the web page to the I2C module or device.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

Bart95

Thank you for your answer, but I did it in the way you explained, the new version is in place and I tried to run "I2C command" as written in the readme
4.1) "I2C Demo" where you can send commands via UEXT using I2C interface to any connected module. The address, command and data must be a single-byte values.

Do you have another advice ?

Stanimir5F

#3
Hi Bart95,
I'm not sure if I understand your problem completely so I will give you a suggestion but please excuse me if it's useless :)

First of all that demo was tested with Olimex board MOD-IO as a slave board. So if you are using another board (quite possible) you should edit some things.

There is a list of commands which could be executed. Check in file "Custom_MOD-IO.c" the function MOD_IO_Command. There are few case clauses with the valid command codes (for MOD-IO they are: 0x10 - Set relays; 0x20 - Get digital inputs; 0x30/0x31/0x32/0x33 - Get analog input channel (1/2/3/4); 0xF0 - Change slave address). Each of them calls a different function defined below.
So if you are using another slave board the commands will be different and the functions for each of the commands.

Also if you are using read command, it (the command code) should be defined in the program code. Otherwise it will be trashed completely (that means it won't be executed at all). You can see the definitions list on the "CustomHTTPApp.c" line 273. By default it should be something like this:
--------------------------------------------------------------
273:      // List of "Read commands" codes are defined here
274:      #define   READ_DIGITAL   0x20
275:      #define   READ_ANALOG1   0x30
276:      #define   READ_ANALOG2   0x31
277:      #define   READ_ANALOG3   0x32
278:      #define   READ_ANALOG4   0x33
--------------------------------------------------------------
Here you can extend the list of commands (and also remove any of them if you don't need them).

And few lines below there is a condition if the command on the value inside the "Command" box is any of the described:
--------------------------------------------------------------
289:         // check if the command is in fact "READ"
290:         if (!(
291:               Command == READ_DIGITAL ||
292:               Command == READ_ANALOG1 ||
293:               Command == READ_ANALOG2 ||
294:               Command == READ_ANALOG3 ||
295:               Command == READ_ANALOG4
296:             )
297:            )
--------------------------------------------------------------
You have to add the defined code(s) above to the if condition.

If this isn't helpful please describe me more your problem.


Stan, Olimex
May the Source be with You!

Bart95

Hi Stan
As I said in my first post, It was a test "out of the box" without any slave board attached to the PIC-WEB (just my digital analyzer). I didn't review the C code yet, but your comment show commands are filtered and "READ_DIGITAL   0x20" is defined. So I sent a "6" as address and "32" as command and it works.

Thank you very much  :)