Jump to content

Recommended Posts

I'm attempting to create a slave module with a 16f1519 using 7-bit addressing. I'm confused by the datasheet. It appears that the R/W bit of the 7-bit address is bit 0, but I can't find that defined anywhere.

 

If I read this right, then after the start condition is detected, the master clocks out the 7 address bits. I got that part, but the data sheet sates that the last bit clocked out (bit 0) is ignored. Technically it states that this bit is unused and is a 'don't care' condition in 7-bit slave addressing. So, if I am using 7-bit addressing, how to I tell the slave that the next byte sent is data to be received vs address to be read? Is this something that is handled as part of the slave firmware? That is, the address I create for the slave includes a bit that tells the controller if it is a read vs write operation? If that's the case, it sounds like it is really a 6-bit address with an R/W bit.

 

What am I missing?

Share this post


Link to post
Share on other sites

The definition is in the Philips I2C specification.

 

The master clocks out the 7 bit address plus the R/W bit (bit 0).

The master will take the 7 bit address, shift it 1 bit left and append the R/W bit before putting into the transmit register.

 

The slave will ignore bit 0 when performing the address comparison but the hardware will register the state of bit 0 in the status register so you know what is being asked.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Thank you for clarifying that.

 

Shy of the timing diagrams, and the vague allusion to the status register bit, does the datasheet even really cover this? This is really confusing.

Edited by mityeltu

Share this post


Link to post
Share on other sites

The data sheets are probably not all that clear.

 

Get a copy of application notes AN734 and AN735. These will give you an idea of how to use the status register as a form of state machine.

 

The PIC is not as good as the Atmel devices when it comes to I2C states, but they do work.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

ok. lots of reading there. I'll pry into that tonight.

 

As I see it, I need to send a minimum of 3 bytes to the slave (slave address, slave internal register address, data). Is it possible to send just one byte (slave address) just for the sake of checking communications? For instance, can I do the following:

 

start();

send_byte(slave address);

stop();

 

Since the slave SHOULD have the SSPIF flag set when the address mathces (right?), I would imagine i could just have my slave in an infinite loop waiting for the SSPIF flag to set and then toggle an LED. Is that possible? I ask because that's what I'm trying to do and it is not working.

 

The master is communicating (checked on scope), but the slave isn't responding.

Share this post


Link to post
Share on other sites

Yes you can just send the address byte. The stop will reset everything.

 

The sspadd must be the address shifted left one bit same as you are transmitting.

 

The slave mode should be 0110 = slave mode 7 bit.

 

You won't get an ACK back until you read the ssbuf and clear any clock stretching.

The interrupt flag will be set on address match and cleared when you read ssbuf.

 

I don't use the supplied libraries so am not familiar with what they do.

I am all interrupt driven so roll my own depending on needs.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...