BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 7:52 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Example code for HW I2C on BAP Needed
PostPosted: Sat Jan 14, 2012 4:40 pm 
Offline
Citizen

Joined: Fri May 06, 2011 8:19 am
Posts: 11
Can someone point me to example code where the BAP is using the hw i2c capability as a master? I've tried searching and haven't found anything yet. Been going through the h8/3687 hardware manual and been trying to duplicate the flow charts and examples, but can't even get it to successfully issue a start condition.

I'm actually trying this on a Mad Hatter. SDA is hooked up to A4 and SCL is on A5 (same as Arduino). I don't see this talked about in the Mad Hatter manual, but I assume it's the same as an Arduino. Also have 4.7K pull-ups on SDA and SCL.

FWIW, I can bit bang these pins with the exact same HW setup and get the slave to respond. Just trying to make HW I2C work.

Here is the code fragment of what I've tried so far:

main

ICCR1.Bit7 = %1 ;set ICE (bit 7) in ICCR1 to 1 (%10001111)
ICMR.Bit7 = %1 ;set MLS (bit 7) to 1
ICMR.Bit6 = %1 ;set WAIT (bit 6) to 1
ICCR1.Bit3 = %1 ;set CKS3 to 1 in ICCR1 (bus clock speed)
ICCR1.Bit2 = %1 ;set CKS2 to 1 in ICCR1 (bus clock speed)
ICCR1.Bit1 = %1 ;set CKS1 to 1 in ICCR1 (bus clock speed)
ICCR1.Bit0 = %1 ;set CKS0 to 1 in ICCR1 (bus clock speed)

Test_BBSY
If ICCR2.Bit7 = 0 then Bus_Free ;test to see if BBSY (bit 7) in ICCR2 is equal to 0 (bus not busy)
goto Test_BBSY

Bus_Free

ICCR1.Bit5 = %1 ;set MST (bit 5) to 1 in ICCR1
ICCR1.Bit4 = %1 ;set TRS (bit 4) to 1 in ICCR1

ICCR2.Bit7 = %1 ;set BBSY (bit 7) to 1 in ICCR2
ICCR2.Bit6 = %0 ;set SCP (bit 6) to 0 in ICCR2 - this should create a "start" condition

ICDRT = %00010000 ;send control byte to slave device

Test_TEND
If ICSR.Bit6 = 1 then TEND_1
goto Test_TEND

TEND_1
...


Top
 Profile  
 
 Post subject: Re: Example code for HW I2C on BAP Needed
PostPosted: Sun Jan 22, 2012 11:01 am 
Offline
Citizen
User avatar

Joined: Thu Feb 17, 2011 3:17 pm
Posts: 18
Hi Inh,

It certainly is possible to get the HW I2C working on the H8/3687. I've done the same as you and followed the datasheet flowcharts to implement Master Transmit mode in ASM on the ARC-32. I couldn't find any examples to follow either.

I found when following the datasheet, it sometimes used the word Set to mean 'give a value' rather than '= 1'. This tripped me up a number of times. What you should do for your setup is something like this this:

ICCR1.ICE = 1
ICMR.MLS = 0 (Specifies order bits are sent in)
ICMR_WAIT = 0 (Adds an extra time delay that caused me numerous problems when set)

;Set the clock speed to 100KHz (presuming the Mad Hatter runs at 20MHz like the ARC)
ICCR1_CKS3 = 1
ICCR1_CKS2 = 1
ICCR1_CKS1 = 0
ICCR1_CKS0 = 1

Then the rest is the same as what you've done, except that you need to wait for TDRE to become 1 after clearing SCP. Then write the slave address and check for TEND. Then you can continue to send data bytes such as the command and values. Other than those things It looks ok to me. If you are still unable to get a start condition then that may be something specific to the Mad Hatter.

Good Luck,
-1


Top
 Profile  
 
 Post subject: Re: Example code for HW I2C on BAP Needed
PostPosted: Wed Jan 25, 2012 11:00 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
You also can't use the bit modifiers when sending a Start or Stop. The two bits must be set as specified all in one instruction. Eg reg = 0xXX, not reg.bit7 = X: reg.bit6 = X.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO