Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:53 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : I2C LCD

     Page 3 of 4    
Author Message
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 08:56pm 18 Jan 2014
Copy link to clipboard 
Print this post

  TZA said  Once you get a led flashing, you are on your way. :)


I think it is time to call it quits on this one. No point in bashing one's head against the wall.

I have tried every trick in the book, both logical and il but can not get the second 8 bit port to do anything nor can I get either port to read in pin status. Anything I try and do on port b shows up only on port a.

I have scoured the web - many people having problems but no solutions that made sense. One chap alluded to a vital command that is not well known but the solution was not code so couldn't work out from it what to do.

The MCP23018 looks like a mongrel chip. If anyone has used one successfully, I'd love to know. It all looks so simple.

Every other I2C device I have whether bought or home grown all work fine. Just Dunno.
David M.
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 09:40pm 18 Jan 2014
Copy link to clipboard 
Print this post

No don't quit yet

MCP23018 which is basically the same as the 23017 except it has an open collector and 5v tolerant pins

so take a look here
MCP23017
And here

More MCP23017

Regards
John
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 01:07am 19 Jan 2014
Copy link to clipboard 
Print this post

Hi John,

That initialise routine is much the same as I have been trying. Anyway, I set it all up the same as per your routine and get absolutely zip. All the commands return MM.I2C "0". Beginning to think it is a hardware problem. I made a new chip carrier board and soldered in the second chip with the same results.

I set up the circuitry to accommodate the open drain ports. I'll download the mcp23017 datasheet and see if there is any difference. Last resort.

I'M fair flummoxed!


David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 01:32am 19 Jan 2014
Copy link to clipboard 
Print this post

Just as an aside,

The device is in default bank 0 on POR or /reset. So, writing &HA0 to register &H0A will set the Bank bit (7) to 1 which will put it in bank 1 mode. Then writing to register &H0B appears to do nothing as there is no register &H0B in bank 1.

puzzled.


======

I wrote &HA0 to all three iocon regs 0A, 0B and 05 and now I'm getting activity on port b. Haven't had that before. Didn't see that in the datasheet. Too late at night - continue tomorrow.Edited by MOBI 2014-01-20
David M.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:09am 19 Jan 2014
Copy link to clipboard 
Print this post

Aha progress!
That little chip must obey!

Unfortunately i am not much of help as i did not use one of those chips in my own coding.

Thanks Mobi for figuring this thing out. I am sure many will benefit from your efforts.


Microblocks. Build with logic.
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 08:39am 19 Jan 2014
Copy link to clipboard 
Print this post

Hi
To get that little chip to obey :) try this


Init23017:

I2CSEND i2caddr, 0, 2, &H0A, &B10100000
I2CSEND i2caddr, 0, 2, &H0B, &B10100000

I2CSEND i2caddr, 0, 2, &H05, &B10100000
I2CSEND i2caddr, 0, 2, &H00, &B00111111
I2CSEND i2caddr, 0, 2, &H06, &B00111111

I2CSEND i2caddr, 0, 2, &H10, &B00000000
I2CSEND i2caddr, 0, 2, &H19, &B00000000

Return

Then use this to send and check the status

I2CRCV i2caddr, 0, 1, Buttons, 1, &H09 ' This will check port A inputs

I2CSEND i2caddr, 0, 2, &H19, temp ' This will write to port B
I2CSEND i2caddr, 0, 2, &H09, temp ' This will write to port B

Regards
John
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 11:59am 19 Jan 2014
Copy link to clipboard 
Print this post

Obey! Obey or you will be exterminated!
Smoke makes things work. When the smoke gets out, it stops!
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 02:49pm 19 Jan 2014
Copy link to clipboard 
Print this post

Now where did I leave that sonic screwdriver?

John, thanks for the code - I had a look at your earlier posting - I must confess I didn't look at your links at the time.
I extracted the appropriate section last night and that is when I started getting activity on port b (for the first time).

The only thing I was doing differently was doing all operations in bank 0 (I'm convinced it still can) Anyway one headache at a time - get it working first.

It all appears to be doing what it should but the open drain system means lots of resistors and leds etc.

I've also come to the conclusion that the chip does not like "noise". Floating pins seem to be a problem and the system locks up. I commented out lines 2 and 3 and it all still works. Port b seems to NEED pullups on.

I'm going to redo the mock-up so that I can write data to a port and read it back from the other port and display on screen (or i2c display?). Fingers crossed.


I2CSEND i2caddr, 0, 2, &H0A, &B10100000 'select bank 1 mode (separate registers) and non-sequential read.
'I2CSEND i2caddr, 0, 2, &H0B, &B10100000 'this would do nothing as address &H0B now is now not in bank 1
'I2CSEND i2caddr, 0, 2, &H05, &B10100000 'same as for line 1 - because of iocon register pairing, so not needed

I2CSEND i2caddr, 0, 2, &H00, &B00111111 'pin data direction port a 0=output 1=input
I2CSEND i2caddr, 0, 2, &H10, &B00000000 'pin data direction port b

I2CSEND i2caddr, 0, 2, &H06, &B11111111 'port a weak pullups
I2CSEND i2caddr, 0, 2, &H06, &B11111111 'port a weak pullups

I2CSEND i2caddr, 0, 2, &H19, &B00000000 'clear port b outputs

Return

Then use this to send and check the status

I2CRCV i2caddr, 0, 1, Buttons, 1, &H09 ' This will check port A inputs

I2CSEND i2caddr, 0, 2, &H19, temp ' This will write to port B
I2CSEND i2caddr, 0, 2, &H09, temp ' This will write to port A
Edited by MOBI 2014-01-21
David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 06:39pm 19 Jan 2014
Copy link to clipboard 
Print this post

Hi Jman

Thanks for the inspiration. I think all my problems were noise related.I've swept the floor and collected all the hair. Now who is that hair transplant mob?

I commented out the weak pullups as they shouldn't be needed as port b is output with resistor and led external pull ups and port a is tied to logic levels from port b.

IOCON only needs initial set up at &H0a as the registers concerned are shared.
The numbers on the 7seg display are just 1 2 4 8 and nothing to do with the expander, just an indicator that the i2c bus was working so I left it in.

The expander is in that block of connectors in the foreground.






Mode 4
Cls
4 x7segdisp = &h38 'i2c device address (LED)
expander = &H20 'i2c address expander

Dim inpina 'data read from 8bit wide port a
Dim inpinb 'in case needed
dim number 'value 0 to 255 entered at keyboard

'Bank 1 mode

iodira = 0
iodirb = &H10
iocon = &H0a
'ioconb = &H0b
gppua = &H06
gppub = &h16
gpioa = &H09
gpiob = &H19
olata = &H0a
olatb = &H1a

I2CEN 100,100 'enable the i2c bus

I2CSEND expander,0,2,iocon,&Ha0 'set config bank 1

I2CSEND expander,0,2,iodira,&Hff 'port a inputs
I2CSEND expander,0,2,iodirb,&H00 'port b outputs

'I2CSEND expander,0,2,gppua,255 'port a pullups
'I2CSEND expander,0,2,gppub,255 'port b pullups

I2CSEND expander,0,2,gpiob,&Hff 'clear port b output

I2CSEND disp,1,5,0,1,2,4,8



start:

Input "Enter number 0 to 255 ",number
Cls

I2CSEND expander,0,2,gpiob,number
I2CRCV expander,0,1,inpina,1,gpioa

Print "The number sent is " number 'send byte to port b
Print "The number received is " inpina 'receive echo byte from port a
?
?


GoTo start



David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:30pm 19 Jan 2014
Copy link to clipboard 
Print this post

The expander also works in bank 0 mode just by substituting the corresponding bank0 register addresses.

Moral of the story, NEVER leave pins floating. I got lazy and tried to use just the one pull up resistor and LED on the expander port pins one at a time. I guess in the past I just got lucky.

The same thing applies to decoupling capacitors ALWAYS fit one to the vdd vss pins. I have been caught with that one even though mostly I've got away with it.

The long and the short of it - all works on the expander just as it looked like it should have. Just call me baldy now.
David M.
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 09:48pm 19 Jan 2014
Copy link to clipboard 
Print this post

Glad to hear it's all good

John
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:52pm 19 Jan 2014
Copy link to clipboard 
Print this post

Great news! Like a movie with a satisfying end. :)
Thanks for the hard work!

Microblocks. Build with logic.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 08:18pm 20 Jan 2014
Copy link to clipboard 
Print this post

@TZA

Now that has put the data expander to bed, we can start on turning the PIC16F1503 into an I2C slave and see if we can get it to act as an I2C LCD display.

I cleaned up (syntax wise) a F88 programme I had and successfully dumped it via MPLABX IDE to the 1503. Of course, it doesn't do anything yet. First I'll flash a led to let me know it is working and then I'll fix up the I2C slave mode and flash another led. Different registers, different location and names. Let you know how I go along the way.




Picture is a bit fuzzy but that's hardly surprising.

David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:54pm 20 Jan 2014
Copy link to clipboard 
Print this post

Pic Slave.

Ok, so I didn't flash a LED but a square wave on the cro is as good as a nod to a blind horse. The internal clock tripped me up a bit, needing a register and config words both set up right. Now for the I2C bit.

.......
David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 04:39pm 21 Jan 2014
Copy link to clipboard 
Print this post

Has anyone ever tried to make sense of the Microchip spi/i2c section of the data sheet for 8 bit pic micros and came away with a positive result and their sanity?

Whoever writes their stuff should be stuffed. I went through it a few years ago and got it it working (after many days) but didn't document my source code as intensely as I should have, so currently doing a re-learn. The source code works ok, but if I want someone else to understand it too, I gotta go back to the registers concerned and work out what each bit/byte does.

When writing their data sheet, Microchip tried to do it in narrative form to make it simple, but in the process made it too long, too complex and vague/ambiguous. I guess it is not the last time I'll growl at Microchip!
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 04:53pm 21 Jan 2014
Copy link to clipboard 
Print this post

They certainly like their datasheet writing!
I suppose that is a good thing, as PERHAPS(?) better to have an overdose of information, then a lack of it...

But I hear what you are saying. I seem to recall that the PDF for the PIC32 used in the full MM is about 500 pages - heck!

Billy Connolly has mentioned in his act, that Americans like to give an overdose of informations. He said: "If you buy a transistor radio in America, there's 18 pages about how to turn the f***ing thing on!"


Smoke makes things work. When the smoke gets out, it stops!
 
vasi

Guru

Joined: 23/03/2007
Location: Romania
Posts: 1697
Posted: 05:49pm 21 Jan 2014
Copy link to clipboard 
Print this post

  MOBI said   Has anyone ever tried to make sense of the Microchip spi/i2c section of the data sheet for 8 bit pic micros and came away with a positive result and their sanity?


Nope! I never liked that mix. When I saw the rivals (I won't name them) counterpart, I thought that is impossible to be that simple and still functional. A good solution for me is to use ready made libraries and examples.
Hobbit name: Togo Toadfoot of Frogmorton
Elvish name: Mablung Miriel
Beyound Arduino Lang
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 06:37pm 21 Jan 2014
Copy link to clipboard 
Print this post

  Vasi said  When I saw the rivals (I won't name them) counterpart, I thought that is impossible to be that simple and still functional.


I guess you are talking about Atmel. If so, I found them much easier to understand and usually had C code examples - much easier (for me anyway) to understand. I really should have taken up with AVR in the first place but as much as I don't like Microchip's abysmal documentation, I really am quite fond of the PIC and its physical and instruction simplicity.
David M.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3805
Posted: 09:41pm 21 Jan 2014
Copy link to clipboard 
Print this post

  Grogster said   I seem to recall that the PDF for the PIC32 used in the full MM is about 500 pages - heck!


Over 1000, but split into about 30 sections - one each for the major features (PMP, UART, SPI, USB, DMA, and so on).

The many pages explaining every peripheral port's bit settings seem useful and form most of it.

It could be much smaller if it failed to tell you what is what (many companies follow this philosophy) or didn't provide so many peripherals (which would be silly).

SPI is 60 pages.

Examples are generally in C.

I'm not going back to PIC16/18 without a very compelling reason.

John
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 05:11pm 22 Jan 2014
Copy link to clipboard 
Print this post

  JohnS said  I'm not going back to PIC16/18 without a very compelling reason.


I don't blame you, but some of us (maybe not on this forum) actually like playing with assembly language and to keep it simple, an 8bit pic does nicely if you don't mind masochistically bashing your head against Microchip documentation brick walls.

I had another little hiccup over the last 24hours - in translating the F88 pic source to F1503 as an I2C slave. I foolishly chose an I2C address for the chip of 255 (hex FF) and wondered why the MM wouldn't talk to it. Forgot MM does range checking. Changed the address to &b00111111 and voilla! it works.

Now to see if I can make the code into a LCD slave. Haven't checked if I have enough pins as the pic is only 14 pin.
David M.
 
     Page 3 of 4    
Print this page
© JAQ Software 2024