PIC 16F88, smBUS

Status
Not open for further replies.

Misterbenn

Active Member
Hi i'm using the 16F88 (with its I2C) serial comunication module to comunicate with a smBus slave. the two are ment to be able to comunicate in this way.

I'm having some problems with the code and wondered if anyone can help.

Firstly the 16F88 is in Master mode, so will be providing the start and stop conditions. As far as i can see i have to create these in programing. would this assumption be corect? and i think i do this via manipulation of the TRISB register.

Also after i've sent the start bit how do i go about sending the 7 bit address, does this automaticaly send when i load data into the SSPBUF register....or do i need to trigger a transmit flag?

and finaly how do i detect the acknolage bit, is this also down to my programing, or will the PIC automaticaly create a flag?

Thanks for any help you can give me.

P.S i know its not the best programing language for this kind of thing but i only really know assembeler, my knowlage of C and C++ is limited .... if you could keep this in mind when offering suggestions. Thanks
 
The hardware on the 16F88 is only really able to act as an I2C slave. To implement master mode you will have to do everything in software. Have a look at **broken link removed**

You might be better using a device that has a MSSP such as the 16F876 as this can do Master I2C in hardware. Unfortunately, there is no 18 pin device with a MSSP.

Mike.
 
Thanks alot guys, thats really helpful!
Bananasiong, in the code you gave me a link to could you just confirm with me what exactly the 'CBLOCK' is doing.

Would i be right in assuming its creating registers to store all the needed info in. Where is it creating these / how can i find out where they are being created?

thanks.
 
CBLOCK should have an address after it. The code is written to run with bank 1 selected so that the TRIS registers are easily accessed. This means the CBLOCK should be followed by an address in bank 1 -0xa0 is the first available bank 1 address. Alternatively you could use the common area at 0x70-0x7f.

What device are you intending to access on the bus?

Mike.
 
My trying to access a Li-Po Battery charger, and then instruct it to charge and things.

Currently (and with this PIC) i'm only trying to confirm that i can get the charger working ie- charging within safe limits.

Later on i'll be using an AVR - the ATmega406. this will then be controling the charger as well as the discharging of the battery in question. With some luck i'll be able to arange it in such a way that any smart battery can be used in this system.

as for the address for CBLOCK, does it matter if i use the general purpose registers at A0h -EFh? or as u mentioned should i use the "common"? (accesses) area at 70h - 7Fh

how would this then be writen?

CBLOCK 70h ???
 
You can use either area but if you use 0xA0 then you have to switch to bank 1 in order to read/write to the variables prior to calling the routines (and after). If you use the common area then the bank switching is no longer required.

It is indeed written,
CBLOCK 0x70
(I think MPLAB still accepts 70h instead of 0x70)

What chip is the charger? It sounds like an interesting chip.

Mike.
 
Its a Maxim 1647 - universal charger
i will also be using a constant current LED driver from linear tech the LT3474 - this will be used as my load for discharging.

Saddly the battery i have atm isnt a smart battery - but idealy i'll get my system to ask the battery what charge current and voltage it needs.

I also hope to be able to charge and/or drive the load from a variable power source (for my demonstration i'll be using a bicycle dynamo). The idea is that the battery will charge when no load is present - and the load will be shared when there is a load present. i still need to think of some kind of clever power switching for this bit.

Thanks for your help guys. - i'll keep you posted
 
hi again guys -
i've managed to get the pic producing the correct signal - its currently just sending a 7 bit write address.
for the charger i belive the address to be 0001001, and write bit 0 - however my maxim1647 isnt producing a ack responce.

does anyone know the address of generic chargers?

Thanks for all the help so far guys- its been very useful.
 
Hi,
Just found it from the datasheet

This is an example that is easier to understand:
Code:
cblock 0x20
counta
countb
temp
endc
is equivalent to
Code:
counta equ 0x20
countb equ 0x21
temp equ 0x22
 
Code:
cblock 0x20
counta
countb
temp
endc
When you get too many variables racked up in a cblock, this setup:
Code:
	cblock	0x20
		counta,countb,temp
		var4,var5,var6
		var7,var8,var9
	endc
works well to clean things up. You can put as many as you like on each row and have as many rows as you need (up to the amount of RAM, less some stack space). No comma at end of rows. The extra indent for the var names isn't necessary. Sometimes I do it and sometimes not.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…