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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Michael Karas
01/03/12 06:23
Read: 357 times
Beaverton Or
USA


 
#185287 - Leave as ASM
Responding to: Mahmood Elnasser's previous message
I do not know why your I2C bit banging did not work in C - I have done that in C on multiple architectures and had it work just fine - but you may want to consider just leaving it in ASM code and interface that to the rest of your program that is in C.

Some C compilers have an option whereby you can compile a C module to an assembly listing file. This can be useful for helping to get the interface to an ASM routine setup correctly. You write the C framework for your intended ASM function and then compile to the listing. Take the resulting listing and wrap that around your ASM bit-bang I2C code and you end up with a module you can link to the rest of your program.

Life is even easier with some other C compilers that have provisions for "inline assembler code". You can make the interface to the bit bang routine in C and keep it that way but plunk your ASM code down into the middle of the functions. If you use the inline technique your code is sometimes easier to maintain but there can be subtle issues on register usage of the compiler that you need to understand.

Michael Karas


List of 9 messages in thread
TopicAuthorDate
MLX90614 IR Thermometer      Mahmood Elnasser      01/02/12 13:23      
   Leave as ASM      Michael Karas      01/03/12 06:23      
   RE: "I need to do it in C" ??      Andy Neil      01/03/12 13:20      
      let me guess      Stefan KAnev      01/03/12 23:24      
      Sensor gone      Mahmood Elnasser      01/04/12 09:39      
         the main diffrence between SMB and IC      Erik Malund      01/04/12 09:48      
   SMBus is like I2C....      Neil Kurzman      01/03/12 21:01      
      a likely cause        Erik Malund      01/04/12 07:48      
   Which PIC?        Kalpak Dabir      01/08/12 18:42      

Back to Subject List