Menu

Translate A= (1<<Xbit)|(1<<Ybit)

Help
Erdy
2015-02-21
2015-02-27
  • Erdy

    Erdy - 2015-02-21

    Hello,

    Playing with the TWI/I2C Harwdare of AVR ATMEGA328P (Arduino Pro Mini).

    Here is the only short way found to translate the following C code to GCB

    C code for TWIStop

    source : void TWIStop(void){
    TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);}

    GCB code :

    Sub TWIStop()
    TWCR = 0b10010100 ' TWINT|TWSTO|TWEN
    End Sub

    It would be better to use the constants TWINT, TWSTO and TWEN in the code ?
    I tried my poor avr assembler, gcb scripts, ... found nothing else that was not ultra bloat.

    Anybody has a idea on how to do that ?

    Erdy

     
    • Anobium

      Anobium - 2015-02-21

      Perfect timing.

      Send me a personal messages and we can join two projects together. I started this on Monday. 😃. I have two init working so far. This should take a few days to sort.

      The goal is to provide TWI in the planned release.

      Perfect timing.

       
  • Erdy

    Erdy - 2015-02-21

    I must be a nut, I can't find a way to send you a personal message ! Help(Help) :-)

    I have a 'elementary' working TWI include file and there is no secret about it, I can post it here, except it's not 'finished', for now it only scans the I2C address but it's only a matter of time :-).

    Erdy

    BTW, I can find nothing on this forum : quote/code/... :-)

    PS : OK, I Found the big blue button up rigth in your profile

     

    Last edit: Erdy 2015-02-21
  • Anobium

    Anobium - 2015-02-21

    😊

    I am integrating into HWI2C.H so we can port directly from a Microchip to AVR microcontroller.

    I am back home on Sunday my time so I can work on this.

     
  • Anobium

    Anobium - 2015-02-23

    For anyone following this thread.

    I have a replacement HWI2C.H that now supports AVR and TWI communcations.

    Testing has been completed with successful results, thank you everyone. The revised HWi2C.h file supports the GCB HWI2C command set and this means that you can change the chip type with no changes to the IC2 or TWI command set.

    Testing has included mega8, 168 and 328p with regression testing with 16f1938 and 16f1939.

    If you want this file before the release then personal message me. Why? I am awaiting a code review with Hugh before releasing to SourceForge.

     
  • Anobium

    Anobium - 2015-02-24

    Latest status.

    Code is stable on long term tests and I have implemented assembler to improved Master mode performance.

    Send me a PM if you can test please.

     
  • Erdy

    Erdy - 2015-02-27

    Hello,

    Best solution found to translate this C Code :

    TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
    

    Is to use GCB AVR inline assembler

    ldi SysValueCopy, (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)
    sts TWCR,SysValueCopy

    Erdy

     

    Last edit: Erdy 2015-02-27

Log in to post a comment.