PDA

View Full Version : Using I2C with FullSpeed USB



Demon
- 7th July 2006, 22:17
Hi,

I was finally able to get my USB Device recognized and working, but I encountered a serious problem as I was adding functionality. It seems that the I2CREAD command takes too much time and the USB service is lost.

Does anyone have any ideas on how to get around this problem? The I2C device I am polling is a MCP23016 I/O expander.

Robert
:)

Demon
- 7th July 2006, 23:03
I have one idea, I'd like opinions on it please. Lack of experience prevents me from knowing if I am just heading for another set of problems.

How about adding a PIC 16F628 to poll the MCP23016 and use hardware USART to send a word whenever data from the I/O Expander changes?

I checked the datasheet and the 16F628 can go up to 5000 KBAUD at 20MHz while in Synchronous mode. Is that fast enough without the USB service dropping?

Robert
:)

Charles Linquis
- 7th July 2006, 23:38
If you have a device with a hardware I2C port, you could use that instead of PBP's bit-banging ones. The hardware approach would take a lot less CPU cycles.

Demon
- 7th July 2006, 23:59
Can you elaborate just a bit more please?

Robert
:)

Charles Linquis
- 8th July 2006, 00:30
A lot of the newer PICs have a hardware I2C port. The 18F8722 for example, has two ports. Microchip calls these "SSP" or "MSSP" ports.

Just as SERIN and SEROUT use pure software to manipulate ports, I2CREAD and I2CWRITE use software to simulate a true hardware I2C port. Since everything is done in software, the processor is tied up 100% of the time during the entire operation.
HSERIN and HSEROUT use the PIC's USART. If these are used, the software simply needs to write to or read from a register, and hardware takes over to send or receive the bit stream. From a processor standpoint, HSEROUT is hundreds of times faster than SEROUT.
The same thing is true with I2C. If you can use the PIC's built-in hardware to do the task, it is MUCH quicker than using I2CREAD and I2CWRITE.
Unfortunately, I'm in the process right now of learning how to use the specialized I2C hardware. As a result, I'm not much of a resource (at least not today) when it comes to actual implementation.

Demon
- 8th July 2006, 00:39
I'm using the 18F4550 as main processor and it has both the USB and SPP features. I have a LCD tied to the SPP port already, and nearly all the other pins are used.

Is there a device that could take I2C input and then output through USART? I know MicroChip has a lot of 'stuff', but I don't have any experience in this area.

Robert
:)

mister_e
- 8th July 2006, 00:42
how many byte do you read at the time?

still working with a single byte at the time? if so, just do loop and insert a USBSERVICE inside

As now i didn't use I2CREAD/WRITE with USB ones so...The MSSP is also suggest by me.

Charles.. i'm with you ;)

Demon
- 8th July 2006, 00:55
Steve, the MCP23016 has 16 bytes and I'm using at least 13 of them.

Robert
:)

mister_e
- 8th July 2006, 01:00
miip 16 bits, 2 bytes. i don't remind how to access to them.. since too much time i don't use them :( can you refresh my single workable brain cell on this friday before i left home to night club :)

Demon
- 8th July 2006, 01:12
D'uh, yeah, bits. :D

I just use I2CREAD for a WORD and get all 16 bits in one shot.

I checked the MicroChip site and they have the MCP23S17 which goes at a maximum of 10MHz in SPI mode. I don't think that's worth the effort to even try.

But I did get another idea; using a 16F628 to read the MCP23016, sets 4 output pins to a binary value (I just need the number of the 1st active pin) and then sets a READY pin. The 18F4550 works on USB until the READY pin is set and then reads the 4 input pins. TADAA!!! Super fast 16 bit parallel exchange between 2 mcus.

I just don't know how the 18F4550 can reset the READY pin though. I never got a full grasp of that concept.

Robert
:)

EDIT: Reviewing my own thread from a while ago:
http://www.picbasic.co.uk/forum/showthread.php?t=2861&highlight=busy+line

mister_e
- 8th July 2006, 01:33
mmm, that make me think of few things to try on sunday... i'l do some test with the 4550 and I2C... Anyways i guess that one project i have in head will probably need at least one I2C external device... so i'll hae to mess with I2CREAD/WRITE and/or MSSP anyway.

Your point is valid but need extra hardware... sure workable, but it have to be done without it. The MSSP is the one i mostely suspect workable. SPI is faster than I2C... but MSSP i2C is more fast than PBP I2CREAD/WRITE

mmm...

Demon
- 8th July 2006, 02:00
Steve, I don't have much choice. The SPP feature on the 18F4550 has only 8 bits, I need at least 13.

I wonder if I can do this with discrete components instead of using the MCP23016 and 16F628 to generate a 4 bit combination. I have 13 momentary push-buttons that I have to get to the 18F4550 as fast as possible.

I'm sure there's another way. I'll ask on an electronics forum and see what the gurus there come up with.

Robert
:)

mister_e
- 8th July 2006, 02:15
Sure it have 8 bits... 2 successive read .. well something like stated somewhere in the MCP datasheet. It must exist a quick drwaing of it somewhere in.

if you really want to add stuff, 4 choice spring to mind

use a bigger PIC than the 16F28, then just read the i/o, send it to the 4550 via USART.

Use a keypad decoder like 74c922

Use a single (or more) A/D pin of the 4550 with a multi-step voltage divider... yisssh

Find a multiplexer... time is short now, but it have to exist, i had the 4067 idea... but i'm not sure... i must forget something on this chip.. what? i don't know.

Demon
- 8th July 2006, 03:08
I like the 74C922 keypad decoder, looks simple enough.

Robert
:)

EDIT: Hmmm, looked simple enough until I saw the prices at DigiKey and Mouser. It's 1/2 the price to go with a MCP23016 and PIC 16F628.

Demon
- 8th July 2006, 03:48
Steve, the 4067 multiplexer/demultiplexer is even better and only $2.08CAD at DigiKey.

The only problem is that I don't understand how to get it to go 'backwards'. The A0-3 pins are always referred to as inputs, I need them as outputs. I'm sure there's a way 'cause these are called both names, they must process both ways, no?

Robert
:)

EDIT: "The CD74HC4067 and CD74HCT4067 devices are digitally
controlled analog switches that utilize silicon-gate CMOS
technology to achieve operating speeds similar to LSTTL,
with the low power consumption of standard CMOS
integrated circuits.
These analog multiplexers/demultiplexers control analog
voltages that may vary across the voltage supply range.
They are bidirectional switches thus allowing any analog
input to be used as an output and vice-versa. The switches
have low “on” resistance and low “off” leakages. In addition,
these devices have an enable control which when high will
disable all switches to their “off” state."

It should work.

Demon
- 8th July 2006, 04:52
74HC148 encoder here:
http://www.st.com/stonline/books/pdf/docs/1903.pdf

Page 7 has a schematic to cascade 2 chips with 16 inputs to 4 outputs. $0.31CAD when I buy 100 at DigiKey and I only need an AND and NOT gates to go along with them.

Robert
:)