Jump to content
Sign in to follow this  
toshen

Need Help With 16f877

Recommended Posts

;) Hey Guys. First of all nice to meet some dudes with the same probs as me.

I´m programming a pic16f877 right now and have to initialize the i2c. The controller has to recieve datas from 4 pic 16f870 and a ds 1307 realtime-clock.

Although the controller has to recieve and trancieve datas from 24c64 EEPROM via i2c.

Can you help me to getting in to it?

I´ve only experiences with keil programming with the rs232 wich is a lot different to the ide and i2c.

I finished the hardware allready, and started the programm wizzard of PICANT to initialize the ports ( in/out/adc ) yet. Now I have a big questionmark in my face how to go on. Please help me.

Share this post


Link to post
Share on other sites

toshen,

 

Can noone give me some starting advices?

I think you ask for too much at once, and what you are asking for is not so clear.

 

Regards

Dave

Share this post


Link to post
Share on other sites
toshen,

 

Can noone give me some starting advices?

I think you ask for too much at once, and what you are asking for is not so clear.

 

Regards

Dave

Ok you´re right. I want the configuration code for the i2c bus for the pic 16f877.

Can I go on with:

void main (void)

{.

.

.

SSPSTAT = 0x80;

SSPCON1 = 0x2e;

.

.

.

}

 

?

Share this post


Link to post
Share on other sites

;) How do I set the 10-bit address for a pic 16f870?

In which register do I have to write that?

Is there another function to set things like that instead of main?

Share this post


Link to post
Share on other sites

toshen,

 

Have a look in the BoostC help file under I2C.

 

Regards

Dave

Share this post


Link to post
Share on other sites

toshen,

 

I have to agree with Dave on this. You have asked for a lot.

 

From July of last year until November I search the internet, Microchips web site, Philips web site and ended up hiring a more experienced consultant to help develop just a small part of what you have ask for.

 

You would do yourself a favor by at least trying to show that you have done some research.

 

On the Microchip web site find AN578 "Use of the SSP Module in the I2C Multi-Master Environment".

 

On the Philips web site find "The I2C-bus specification", document order number: 9398 393 40011, and application note AN10216-01 "I2C MANUAL" and "The I2C-bus and how to use it" is quite useful as well.

 

Reading those documents will at least give you the scope of what you are trying to accomplish.

 

When you get your I2C interface working with 7-bit addressing, 10-bit addressing, and multiple master mode all coded and debugged could I please have a copy of the source code, for free? Please?

Share this post


Link to post
Share on other sites

I looked at AN976 which explains how to hook up a I2C EEPROM to a 16F877A using the hardware I2C logic on the chip. The claim in the app note is that with the hardware you don't have to know the I2C bus and it is very easy. What I found was that it takes as much (if not more) code to use the hardware as it does to just bit-bang the interface. The bit-banging technique allows you to use any two pins to implement the bus and in my opinion is easier to understand. I think the hardware Microchip provided is one layer too low to be very useful unless you have something else to do while transmitting and receiving packets. The firmware to support their hardware has to be way too involved.

 

I agree with cac001 that you should read the Philips info. Also, check out the I2C EEPROM example provided with the BoostC compiler.

 

C:\Program Files\SourceBoost\plugin_examples\bcd_i2c

 

It is a good starting point. I wrote some code before I got turned on to BoostC that you can look at as well (I just ported it to work with BoostC):

 

http://www.geocities.com/ted_rossin/Electronics/Pic/Pic.html

 

Scroll down to Library of C routines to get CBLib.zip and look at the ExtEprom code.

Share this post


Link to post
Share on other sites

it looks to me that torsin is always busy in showing the links or so and that too of his codded lines....

I think that the person is asking the straight question, why the people here give links and all insted of just replying in plain...

Share this post


Link to post
Share on other sites
it looks to me that torsin is always busy in showing the links or so and that too of his codded lines....

I think that the person is asking the straight question, why the people here give links and all insted of just replying in plain...

 

torsin = toshen + trossin?

OK, I'll say it without a link. Most people find example code and links to data sheets and specs more helpful than raw answers as sometimes the answer is wrong or not what was really asked for as an assumption was usually made. In the case below the answer is to write bits 3:0 of address 0x14 with either 0x7 or 0xf. The answer depends on whether or not toshen wants to run in master mode or not.

 

If toshen would look at the data sheet for the SSPCON register the answer would be clear. toshen does not seem willing to do this. The point that others have been making is that using the SPI block for I2C is not trivial and there is not much hope of getting it to work without doing basic research. Asking for the set up values for the registers is not going to get this block working. Reading the data sheet, the I2C spec and looking at example code is how to get it to work.

 

How do I set the 10-bit address for a pic 16f870?

In which register do I have to write that?

Is there another function to set things like that instead of main?

 

Instead of writing:

 

SSPCON = 0x2e;

 

use:

 

SSPCON = 0x2f;

Share this post


Link to post
Share on other sites
If toshen would look at the data sheet for the SSPCON register the answer would be clear.  toshen does not seem willing to do this.  The point that others have been making is that using the SPI block for I2C is not trivial and there is not much hope of getting it to work without doing basic research.  Asking for the set up values for the registers is not going to get this block working.  Reading the data sheet, the I2C spec and looking at example code is how to get it to work.

 

Very well stated, Ted.

Manuals, datasheets, examples... are there to be studied.

 

A good book could help, too: for instance Roger Steven's book about serial comms. Everything a beginner or intermediate programmer really must know about PICs and serial lines. A bit of clearly explained theory, flowcharts everywhere, lots of schematics and hands-on practical examples in assembly, few really noticeable errors in code. Really worth the bucks for who's just starting.

 

For those who don't like links, I will not say that Dave's (Benson) and Roger's books have a reference site: http://www.sq-1.com/ ;)

Share this post


Link to post
Share on other sites
it looks to me that torsin is always busy in showing the links or so and that too of his codded lines....

I think that the person is asking the straight question, why the people here give links and all insted of just replying in plain...

 

For those that dislike links please skip this message.

 

For answers to toshen requests see these links:

 

I2C code on the C compiler forum at CCS

 

I2C discussion thred on the CCS forum

 

BTW, who is torsin? ;)

Share this post


Link to post
Share on other sites

The answer depends on whether or not toshen wants to run in master mode or not.

 

I want to run in Slave Mode for recieving the datas from the 4 16f870 which are in Master-mode and are not connected constant and in Master to Store them on the EEPROM. From there I can get them on my CPU via USB-Driver, that seems to work. I´ve started to programm a touchpanel and an lcd screen, now I want to get the I2C-network programmed. The problem was to get in to it, I only programmed Infineon controllers (reg 164,167) with Keil uVision, what is much easier to handle. But I understand; I´ve just started to study the links you sent me. I´ve no Problems with helpfull links, only with comments like " look in the Help-files", how stupid do you think I am? Ok, my English is not the best, though. HELLO i´m a Japanese....so sorry!

Thanks for the regards I inform you how things are growing...

Greetz toshen :D

Share this post


Link to post
Share on other sites
I want to run in Slave Mode for recieving the datas from the 4 16f870 which are in Master-mode and are not connected constant and in Master to Store them on the EEPROM. From there I can get them on my CPU via USB-Driver, that seems to work.

 

Your request, as it is stated, could be fullfilled by an experienced PIC programmer with a good insight on I2C (and a large field-proven codebase on his HD as well).

 

But things may be made much simpler at architectural level, with little conceptual redesign.

 

First, do not connect the EEPROM to the "main" I2C bus: use a different couple of pins with bitbang (firmware driven) emulation instead. This solves 50% of problems and avoids unnecessary master/slave mode switching and bus arbitration.

 

Second: one slave and four masters sounds alerting to my ears for such a system. Why do you need the 16F870 to drive the transmission ? Cannot data be simply polled ?

Unless there are unavoidable realtime constraints, good practice simply suggests to do the opposite: 1 master and 4 slaves.

 

This way you will have a plain single-master I2C main bus, plus a physically and logically separate I2C emulation to drive the EEPROM. Much simpler to deal with as your first experience in this field.

Share this post


Link to post
Share on other sites

Thanks, so I´ve to change the 16f870 into slaves, I need them because they are messuring analog voltages on a sep. circuit what is neccessary because the voltage can increase up to 90Vdc. I handelt that with iso122 operaters and Dc/Dc changers and one 16f870 for each mess.circuit. I can plug in these circuits optional on a mainboard (4plugs=4 Pics). I sartded to programm the extern interrupts for the touchpanel and recognize that they have to be connected with portz B is that right? Can´t I use port A for the interrupts? Because then I´ve to make a new hardwaredev.

greetz

Share this post


Link to post
Share on other sites
Thanks, so I´ve to change the 16f870 into slaves, I need them because they are messuring analog voltages  on a sep. circuit what is neccessary because the voltage can increase up to 90Vdc. I handelt that with iso122 operaters and Dc/Dc changers and one 16f870 for each mess.circuit. I can plug in these circuits optional on a mainboard (4plugs=4 Pics). I sartded to programm the extern interrupts for the touchpanel and recognize that they have to be connected with portz B is that right? Can´t I use port A for the interrupts? Because then I´ve to make a new hardwaredev.

 

Carefully read the Philips docs before using optocouplers on the I2C bus. You may also have a look at Philips' special ICs like P82B715 and similar.

 

As regards interrupts, only PORTB supports them in the 16F8 series (and in many pin-compatible series, like 18F45x). But you do not really need interrupt for a touch panel. Polling the "touch sense" line a few times per second is more than enough. Are you using discrete transistor/fet switching or a dedicated touch panel controller ?

Share this post


Link to post
Share on other sites

 

 

Carefully read the Philips docs before using optocouplers on the I2C bus. You may also have a look at Philips' special ICs like P82B715 and similar.

 

As regards interrupts, only PORTB supports them in the 16F8 series (and in many pin-compatible series, like 18F45x). But you do not really need interrupt for a touch panel. Polling the "touch sense" line a few times per second is more than enough. Are you using discrete transistor/fet switching or a dedicated touch panel controller ?

 

 

Oh you missunderstood me. I mean isolation amplifier (hope that is the correct translation ) iso122 from BB to isolate the voltages to a max of 4.8V per adc input.

NO optocouplers!!

The tip with the interrupts is very helpfull thanks. So interrupts on a PIC are a lot more complicated then on Infinoen µCs. Unfortunately I have to take PICs...

 

Do you have experinces with picant sourceBoost IDE, how to include existing header files for example for the EEPROM? I just copied the code into my mainfolder and now the compiler says error EOF. But even when I erease the code the error is still there. I already checked out the file endings and comments with no succes.

 

greetz

greetz

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum 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...
Sign in to follow this  

×