CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I2C as slave reading multiple addresses

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

I2C as slave reading multiple addresses
PostPosted: Mon Jul 20, 2009 10:37 am     Reply with quote

Hi. I have a project where we want to replace several Intersil X0241A digital potentiometers with a PIC. There is an existing controller that sends I2C commands to these ePots. We want to read the output values from this controller, with the PIC, and then do our own processing and control. The controller expects the ePots to be in slave mode. I thought at first that I could simply read the I2C address and then the associated data byte, and have the pic perform the desired function. However I see that you have to assign an address to the PIC I2C in slave mode. This would seem to preclude reading more than one output address from the existing controller.

Is there any way to handle this? Is it possible to read the I2C signals from multiple addresses, along with the actual address? (I guess this could be done by bit banging, but I'd rather use the hardware I2C if possible.) I also want to have an interrupt driven input routine so I don't have to tie up my main program loop with handling the input details.

Can anyone give me some suggestions or point me to an article or example?

Thanks, Russ
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 11:21 am     Reply with quote

I'm not sure if I understand what you're trying to accomplish here. Maybe it's because it's Monday or that I had to get up this morning or that I'm at work or just BECAUSE. (Just trying to be funny).

Are you trying to have one PIC simulate all of the pots and have the master talk to it? Or do you want to replace the existing master with one of your own? Would you be able to expand your description on what you're trying to do? The better the description, the better we can understand and give suggestions.

Ronald
PROCRASINATORS UNITE!........... tomorrow
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 12:20 pm     Reply with quote

Quote:
Is it possible to read the I2C signals from multiple addresses, along with the actual address?

Some PICs have an SSP Mask Register (SSPMSK) that allow masking
off bits in the slave address, so they are "don't care" bits. In other
words, it will respond to multiple slave addresses. I've never used this
feature, but I think this may be what you want.

To find which PICs have this feature, do this search in Google:
Quote:
site:microchip.com "SSP Mask register"

Then look in the data sheet to see which PICs in that series have an
SSP module, and can be used as an i2c slave.
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

I2C as slave reading multiple addresses
PostPosted: Mon Jul 20, 2009 2:42 pm     Reply with quote

rnielsen wrote:

Are you trying to have one PIC simulate all of the pots and have the master talk to it? Or do you want to replace the existing master with one of your own? Would you be able to expand your description on what you're trying to do? The better the description, the better we can understand and give suggestions.

Ronald


Hi Ronald. Ok, the original system used the ePots to control the gain of some stages of electronic equipment. There is a controller that addresses the several pots via the I2C bus, sending out an address (8 bit) and value to each one as required. We want to allow users to continue to use the controller, but read the controller's output with the PIC and then control the gain stages with other means. By doing this we will be able to make corrections to the requested values to compensate for changes in things like temperature or non-linearity of the devices.

So there is one PIC that reads any and every I2C transmission from the controller and then does required processing. This PIC is doing a lot of other work as well, so preferably need to only service these I2C inputs when an interrupt indicates that they have been received.

Therefore, I need to be able to read the I2C address that the controller is sending, in order to determine which stage is being adjusted, and then read the value to see what the user intends. As I study this it seems that slave mode is not appropriate, but I am not familar enough with I2C to know if I can read those values using master mode. Perhaps it is that simple?

I looked at the SSP mask register but I do not see how I could determine which address had been transmitted even though I would be able to receive the value. Also the preferred PIC (18F8723) does not have that mask register anyway.

Thanks, Russ
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

I2C as slave reading multiple addresses
PostPosted: Tue Jul 21, 2009 11:52 am     Reply with quote

Well, by the silence I'm getting on this topic today, I'm guessing there is no solution for my problem as stated. So I am going to try another tack. I determined that I really only need to emulate two ePots. That means I only need to act as an I2C slave for two addresses. Since the 18F6723 has two SSP channels, I can do it. However I was already using one channel for SPI control of several devices and so I have to switch this to software SPI using different pins.

My question is about baudrate in software SPI. How can I determine what maximum rate I can use? The help for CCS compiler does not seem to address that. Also I was reading that the USE_SPI command does not work very well when it comes to switching parameters. I need to use different modes for some devices, but I am concerned as to whether I can switch modes 'on the fly' when using software SPI. I am controlling a couple of digital synthesizers, some DACs, and an external EEPROM on the SPI bus.

Is this software SPI a reasonable solution, or should I look at putting a second PIC on the board?

Thanks, Russ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 1:49 pm     Reply with quote

I assume you mean SPI Master mode, done in software.

It's done by bit-banging. Therefore, you control the entire process
and can configure any mode. I wouldn't trust the #use spi() library
until you have tested each mode and looked at the signals.
There were issues with the default settings. Maybe CCS has corrected
these by now, but I don't know.

To find the maximum baudrate, make a test program with a loop
that sends out one byte, repeatedly. Then look at the signals on your
scope or logic analyzer.
russk2txb



Joined: 30 Mar 2008
Posts: 109
Location: New Jersey

View user's profile Send private message

I2C as slave reading multiple addresses
PostPosted: Wed Jul 22, 2009 7:03 am     Reply with quote

Thanks PCM Programmer. I was hoping I could get some indication of speed. The only thing I have found by browsing this forum is that software SPI is "much slower" than hardware SPI. Since it will be about 2 weeks before I have hardware in my hands, I was trying to determine if this is a viable way to go, or if I should go with a second PIC on the board.

There will be a number of tables stored in the external EEPROM and values need to be read from them during operation. I really do not expect the read speed to be so slow that it dramatically affects performance, but I am also concerned about getting hung in the read loop long enough to affect other things - like simultaenously reading 4 channels of A/D and updating DACs according to changes.

So, I wish I had some qualitative information to make decisions with.

Thanks again, Russ
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group