EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / TWI(I2C) ATxmega256A3 for initializing OLED Microdisplay

TWI(I2C) ATxmega256A3 for initializing OLED Microdisplay

|

Microcontroller › AVR › TWI(I2C) ATxmega256A3 for initializing OLED Microdisplay

  • This topic has 0 replies, 1 voice, and was last updated 10 years, 7 months ago by Shivashankar M N.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 11, 2015 at 5:51 am #3614
    Shivashankar M N
    Participant

    Dear Friends
    Please let know how to use the I2C (TWI) communication for initializing micro display during power on.
    The Requirement is to initialize the set of 27 registers in OLED Micro display (act as slave at address 0x64) when powered ON to enable the PAL/NTSC video format.
    The details of default set of values are attached in the file. Please guide me how to implement using C program for microcontroller
    ATxmega256A3BU.
    Datasheet of OLED microdisplay attached.

    I have a code as below. Please let me know how to differentiate slave
    address and registers of the slave address and data to be sent.

    #include <avr/io.h>
    #include "avr_compiler.h"
    #include "twi_master_driver.h"
    #include "twi_slave_driver.h"

    /*! Defining an example slave address. */
    #define SLAVE_ADDRESS 0x64

    /*! Defining number of bytes in buffer. */
    #define NUM_BYTES 27

    /*! CPU speed 2MHz, BAUDRATE 100kHz and Baudrate Register Settings */
    #define CPU_SPEED 2000000
    #define BAUDRATE 100000
    #define TWI_BAUDSETTING TWI_BAUD(CPU_SPEED, BAUDRATE)


    /* Global variables */
    TWI_Master_t twiMaster; /*!< TWI master module. */
    TWI_Slave_t twiSlave; /*!< TWI slave module. */


    /*! Buffer with test data to send.*/
    uint8_t sendBuffer[NUM_BYTES] =
    {0x01,0x78,0x38,0x78,0x38,0x78,0x38,0x81,0x39,0x4A,0x10,0x00,0x02,0x00,0
    x80,0xC0,0x1B,0x07,0x00,0x90,0x0f,0xD8,0x0C,0x01,0x80,0x00,0xC0};


    void TWIC_SlaveProcessData(void)
    {
    uint8_t bufIndex = twiSlave.bytesReceived;
    twiSlave.sendData[bufIndex] = (~twiSlave.receivedData[bufIndex]);
    }

    int main(void)
    {
    uint8_t BufPos = 0;
    // Enable internal pull-up on PC0, PC1.. Uncomment if you don't have
    external pullups
    PORTCFG.MPCMASK = 0x03; // Configure several PINxCTRL
    registers at the same time
    PORTC.PIN0CTRL = (PORTC.PIN0CTRL & ~PORT_OPC_gm) |
    PORT_OPC_PULLUP_gc; //Enable pull-up to get a defined level on the
    switches

    /* Initialize TWI master. */
    TWI_MasterInit(&twiMaster,
    &TWIC,
    TWI_MASTER_INTLVL_LO_gc,
    TWI_BAUDSETTING);

    /* Initialize TWI slave. */
    TWI_SlaveInitializeDriver(&twiSlave, &TWIC,
    TWIC_SlaveProcessData);
    TWI_SlaveInitializeModule(&twiSlave,
    SLAVE_ADDRESS,
    TWI_SLAVE_INTLVL_LO_gc);

    /* Enable LO interrupt level. */
    PMIC.CTRL |= PMIC_LOLVLEN_bm;
    sei();

    TWI_MasterWriteRead(&twiMaster, // Module
    slave_reg[BufPos], // slave address
    &sendBuffer[BufPos], // What to send
    1, // Write how much
    0); // Read how much

    while (twiMaster.status != TWIM_STATUS_READY) {
    /* Wait until transaction is complete. */
    }

    while(1)
    {
    //TODO:: Please write your application code
    }
    }

    /*! TWIC Master Interrupt vector. */
    ISR(TWIC_TWIM_vect)
    {
    TWI_MasterInterruptHandler(&twiMaster);
    }

    /*! TWIC Slave Interrupt vector. */
    ISR(TWIC_TWIS_vect)
    {
    TWI_SlaveInterruptHandler(&twiSlave);
    }

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • restarting this Christmas project November 14, 2025
  • desoldering November 13, 2025
  • Unknown, to me, electric motor fitting November 13, 2025
  • Can a small solar panel safely trickle-charge old NiMH AA batteries? November 13, 2025
  • KiCad custom symbol definition correct approach November 13, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise