froussel / u8glib

Automatically exported from code.google.com/p/u8glib
Other
0 stars 0 forks source link

Arduino Due I2C support request #285

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would love to see more support for the Arduino Due with other communications 
options.  Especially I2C!

Thank you for this amazing Library!

Original issue reported on code.google.com by sh...@xnote.com on 28 Sep 2014 at 12:39

GoogleCodeExporter commented 9 years ago
moved to accepted state

Original comment by olikr...@gmail.com on 28 Sep 2014 at 4:42

GoogleCodeExporter commented 9 years ago
#elif defined(__SAM3X8E__)
#elif defined(ARDUINO) && defined(__SAM3X8E__)

typedef struct {
  WoReg TWI_CR;        /**< \brief (Twi Offset: 0x00) Control Register */
  RwReg TWI_MMR;       /**< \brief (Twi Offset: 0x04) Master Mode Register */
  RwReg TWI_SMR;       /**< \brief (Twi Offset: 0x08) Slave Mode Register */
  RwReg TWI_IADR;      /**< \brief (Twi Offset: 0x0C) Internal Address Register */
  RwReg TWI_CWGR;      /**< \brief (Twi Offset: 0x10) Clock Waveform Generator Register */
  RoReg Reserved1[3];
  RoReg TWI_SR;        /**< \brief (Twi Offset: 0x20) Status Register */
  WoReg TWI_IER;       /**< \brief (Twi Offset: 0x24) Interrupt Enable Register */
  WoReg TWI_IDR;       /**< \brief (Twi Offset: 0x28) Interrupt Disable Register */
  RoReg TWI_IMR;       /**< \brief (Twi Offset: 0x2C) Interrupt Mask Register */
  RoReg TWI_RHR;       /**< \brief (Twi Offset: 0x30) Receive Holding Register */
  WoReg TWI_THR;       /**< \brief (Twi Offset: 0x34) Transmit Holding Register */
  RoReg Reserved2[50];
  RwReg TWI_RPR;       /**< \brief (Twi Offset: 0x100) Receive Pointer Register */
  RwReg TWI_RCR;       /**< \brief (Twi Offset: 0x104) Receive Counter Register */
  RwReg TWI_TPR;       /**< \brief (Twi Offset: 0x108) Transmit Pointer Register */
  RwReg TWI_TCR;       /**< \brief (Twi Offset: 0x10C) Transmit Counter Register */
  RwReg TWI_RNPR;      /**< \brief (Twi Offset: 0x110) Receive Next Pointer Register */
  RwReg TWI_RNCR;      /**< \brief (Twi Offset: 0x114) Receive Next Counter Register */
  RwReg TWI_TNPR;      /**< \brief (Twi Offset: 0x118) Transmit Next Pointer Register */
  RwReg TWI_TNCR;      /**< \brief (Twi Offset: 0x11C) Transmit Next Counter Register */
  WoReg TWI_PTCR;      /**< \brief (Twi Offset: 0x120) Transfer Control Register */
  RoReg TWI_PTSR;      /**< \brief (Twi Offset: 0x124) Transfer Status Register */
} Twi;

#define TWI0       ((Twi    *)0x4008C000U) /**< \brief (TWI0      ) Base 
Address */
#define TWI1       ((Twi    *)0x40090000U) /**< \brief (TWI1      ) Base 
Address */

CKDIV = 3
period = 105 
--> 105*2^3 = 840
CLDIV = 53
CHDIV = 53

TWI0->TWI_CWGR = (53) | (53<<8) | (3<<16)
Set the Control register: Master enable TWI_CR = MSEN + SVDIS
TWI0->TWI_CR = TWI_CR_MSEN | TWI_CR_SVDIS

Original comment by olikr...@gmail.com on 13 Dec 2014 at 7:13

GoogleCodeExporter commented 9 years ago
/**
 * \brief Starts a write operation on the TWI to access the selected slave, then
 *  returns immediately. A byte of data must be provided to start the write;
 * other bytes are written next.
 * after that to send the remaining bytes.
 * \param pTwi  Pointer to an Twi instance.
 * \param address  Address of slave to acccess on the bus.
 * \param iaddress  Optional slave internal address.
 * \param isize  Number of internal address bytes.
 * \param byte  First byte to send.
 */
void TWI_StartWrite(
    Twi *pTwi,
    uint8_t address,
    uint32_t iaddress,
    uint8_t isize,
    uint8_t byte)
{
    assert( pTwi != NULL ) ;
    assert( (address & 0x80) == 0 ) ;
    assert( (iaddress & 0xFF000000) == 0 ) ;
    assert( isize < 4 ) ;

    /* Set slave address and number of internal address bytes. */
    pTwi->TWI_MMR = 0;
    pTwi->TWI_MMR = (isize << 8) | (address << 16);

    /* Set internal address bytes. */
    pTwi->TWI_IADR = 0;
    pTwi->TWI_IADR = iaddress;

    /* Write first byte to send.*/
    TWI_WriteByte(pTwi, byte);
}

void TWI_ConfigureMaster( Twi* pTwi, uint32_t dwTwCk, uint32_t dwMCk )
{
    uint32_t dwCkDiv = 0 ;
    uint32_t dwClDiv ;
    uint32_t dwOk = 0 ;

    assert( pTwi ) ;

    /* SVEN: TWI Slave Mode Enabled */
    pTwi->TWI_CR = TWI_CR_SVEN ;
    /* Reset the TWI */
    pTwi->TWI_CR = TWI_CR_SWRST ;
    pTwi->TWI_RHR ;

    /* TWI Slave Mode Disabled, TWI Master Mode Disabled. */
    pTwi->TWI_CR = TWI_CR_SVDIS ;
    pTwi->TWI_CR = TWI_CR_MSDIS ;

    /* Set master mode */
    pTwi->TWI_CR = TWI_CR_MSEN ;

Original comment by olikr...@gmail.com on 13 Dec 2014 at 7:33

GoogleCodeExporter commented 9 years ago
hw twi does not work without major changes on the u8glib structure --> sw twi
takeover of lpc i2c procedures

Original comment by olikr...@gmail.com on 14 Dec 2014 at 10:14

GoogleCodeExporter commented 9 years ago
Awesome that someone is working on this now. I had a lot of fun with your 
library and a SSD1306 I2C OLED from Banggood on the Arduino Nano. 
I would love to see it working on the due. 

Original comment by Knoch...@gmail.com on 16 Dec 2014 at 11:15

GoogleCodeExporter commented 9 years ago
... but it seems to be more complicated than expected...

Original comment by olikr...@gmail.com on 16 Dec 2014 at 11:58

GoogleCodeExporter commented 9 years ago
also not working with the sw i2c procedures --> create test code with rtc and 
arduino twi code. compare with sw i2c procedures

Original comment by olikr...@gmail.com on 17 Dec 2014 at 6:16

GoogleCodeExporter commented 9 years ago
I'm not a software specialist. But if you like i can do hardware analysis of 
the I2C Bus. So i have access to Oscilloscope wit I2C decoding or Aardvark I2C 
Adapter.

Original comment by Knoch...@gmail.com on 18 Dec 2014 at 1:19

GoogleCodeExporter commented 9 years ago
Thanks, i have an oscilloscope (but without I2C decoding). Actually the bug was 
a missing SLA. 
Everything is now implemented. However only SW I2C will be there.
400KHz and 100KHz option is also implemented. SSD1306 runs fine with 400KHz.
Removing some NOPs will sill allow also 500KHz, which still works.

Original comment by olikr...@gmail.com on 20 Dec 2014 at 4:18

GoogleCodeExporter commented 9 years ago
typical configuration:
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);    // Fast I2C / 
TWI 

Original comment by olikr...@gmail.com on 20 Dec 2014 at 4:18

GoogleCodeExporter commented 9 years ago
Depending on pull up resistor selection, I have had the SSD1306 communicating 
I2C at 1.8Mhz+.  It makes a world of difference on framerate!

Original comment by sh...@xnote.com on 20 Dec 2014 at 7:08

GoogleCodeExporter commented 9 years ago
Yes, i am somehow surprised, that these OLEDs accept such fast communication.

Original comment by olikr...@gmail.com on 21 Dec 2014 at 7:36

GoogleCodeExporter commented 9 years ago
done, documented and tested
Works with both I2C ports

Original comment by olikr...@gmail.com on 21 Dec 2014 at 5:25