Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/10/08 07:08
Read: times


 
#155661 - does it have to be C?
Responding to: ???'s previous message
Chris Bertrand said:
every day my nose is in the "C and the 8051"......

Is it absolutely necessary to use C? - I mean, if you are uncomfortable with it and you apparently are more comfortable with asm, you might better get rid of this one unknown in your task and concentrate on the I2C itself. Note also, that the code you have is an intermix of 4 cases - master transmitter, master receiver, slave transmitter, slave receiver - which you don't need to work simultaneously. And it's not easy to guess the purpose of all those pre-chewed empty function skeletons, so I would simply get rid of them first.

In fact, majority of statements in that code is filling and reading SFRs, which is the same in asm.

Now, the key of the whole I2C stuff is in I2C.C. You don't need to go for the interrupt necessarily, if you can burn processor time freely (i.e. there is nothing else to do in the mcu until transfer is finished) - it might simplify at least the learning phase to do all of the I2C stuff in the "main". In the master, you can simply set the control register so that I2C is enabled and start bit is requested, then wait (poll) for the interrupt flag to come true. If it does, check the status for the appropriate state (to be sure), write the slave address to data register, clear interrupt bit and wait (poll) to come true. You might want to make various checking printouts via UART, just to be sure. Repeat for all bytes to be transferred, then issue a STOP.

As Erik said, this is the best to do with a 24Cxx-series EEPROM, you certainly have one somewhere around (plus the devboard for the LPC9xxs, you might have as well).

You can then try to proceed with the a similar interrupt-less version for the slave. At the moment you will be comfortable with all this, you will naturally move to the interrupt-driven version.


JW


PS. You said this is not the mcu of your choice - can you please tell which one would be?


List of 14 messages in thread
TopicAuthorDate
Hardware I2C on 8051 NXP....I'm stuck            01/01/70 00:00      
   divide and conquer            01/01/70 00:00      
      where would I find that?            01/01/70 00:00      
         what is a "tut file" ??            01/01/70 00:00      
            FIle is in the link in first post            01/01/70 00:00      
               I would NEVER NEVER NEVER .....            01/01/70 00:00      
                  Well that's not gonna happen....            01/01/70 00:00      
                     looks to me as staright CodeArchitect            01/01/70 00:00      
                     accidential double, ignore            01/01/70 00:00      
                     Programming is not guesswork            01/01/70 00:00      
                        blunt is fine.....and I'll say it again.            01/01/70 00:00      
                           Forum posts and reality...            01/01/70 00:00      
                           you will break a leg            01/01/70 00:00      
                           does it have to be C?            01/01/70 00:00      

Back to Subject List