Connect LCD-1x9 to at91sam7s256

Discussion about SAM7 Series and ARM7TDMI based products.

Moderator: nferre

dan18374
Posts: 2
Joined: Wed Dec 14, 2016 1:54 pm

Connect LCD-1x9 to at91sam7s256

Wed Dec 14, 2016 2:04 pm

Hello everyone. I am new to sam7 and ARM in general. I want to connect LCD-1x9(Olimex LCD-MOD-1x9) to at91sam7s256(Olimex board SAM7-P256). I have problems, my LCD does not work at all(it does not light up any segments). May be you know where the problem is? Thank you!

Code: Select all

#include "AT91SAM7S256.h" // Definitions of the ARM chip and on-chip peripherals.
#include "SAM7-P256.h"    // Definitions of peripherals on the Olimex dev board.
#include "Board.h"

#define SPEED_I2C 100000 // operating speed TWI bus in Hz.
#define CLKDIV (MCK/(2*SPEED_I2C)-3) 

void i2c_write_byte(char value)
{
int Status;

    *AT91C_TWI_MMR &= ~AT91C_TWI_MREAD; //Set the recording mode
    *AT91C_TWI_THR = value; //  Writes data to the transmit register, start transmission
    *AT91C_TWI_CR = AT91C_TWI_START;
    Status = *AT91C_TWI_SR; // Read the status register
    while (!(Status & AT91C_TWI_TXCOMP)) 
        Status = *AT91C_TWI_SR; // wait for the completion of transfer
    *AT91C_TWI_CR = AT91C_TWI_STOP;
}

void AT91F_TWI_CfgPIO (void)
{
    *AT91C_PIOA_ASR = 0x18; //assign to PA3, PA4 channel A
    *AT91C_PIOA_BSR = 0x0;
    *AT91C_PIOA_PDR = (0x18 | 0x0); //controlled by peripheral device
}

void AT91F_PMC_EnablePeriphClock (
    AT91PS_PMC pPMC, // \arg pointer to PMC controller
    unsigned int periphIds)  // \arg IDs of peripherals
{
    pPMC->PMC_PCER = periphIds;
}

void AT91F_TWI_CfgPMC (void)
{
    AT91F_PMC_EnablePeriphClock(
        AT91C_BASE_PMC, // PIO controller base address
        ((unsigned int) 1 << AT91C_ID_TWI));
}


void AT91F_TWI_Configure ( AT91PS_TWI pTWI )          // \arg pointer to a TWI controller
{
    //* Disable interrupts
    pTWI->TWI_IDR = (unsigned int) -1;

    //* Reset peripheral
    pTWI->TWI_CR = AT91C_TWI_SWRST;

    //* Set Master mode
    pTWI->TWI_CR = AT91C_TWI_MSEN;

}

int main()
{
    char i;
    
    AT91F_TWI_CfgPIO(); // Connecting TWI to outputs PA3 and PA4
    *AT91C_PIOA_PPUDR = (AT91C_PA4_TWCK | AT91C_PA3_TWD); // Turning off the internal pull-up resistors
    *AT91C_PIOA_MDER = (AT91C_PA4_TWCK | AT91C_PA3_TWD); // Turn control mode - open collector
    AT91F_TWI_CfgPMC(); // allow timing TWI
    AT91F_TWI_Configure(AT91C_BASE_TWI); // Disable all interrupts, do TWI reset and set in the master mode
    *AT91C_TWI_CWGR = ((0x00 << 16) | (CLKDIV << 8) | (CLKDIV));
    *AT91C_TWI_MMR = 0x0;//0 Set the address of the Slave; recording mode; not address internal registers use slave device
    

        //This part is taken from the official Olimex site, there is an example for arduino
        // It is assumed that these lines initialize LCD and light up all segments
    i2c_write_byte(0x70 | 0x00);
    i2c_write_byte(0xC8); // mode register
    i2c_write_byte(0xF0); // blink register
    i2c_write_byte(0xE0); // device select register
    i2c_write_byte(0x00); // pointer register
    
        // light up all the segments, initialize the local display buffer as well
    for(i = 0; i < 20; i++)
    {
        i2c_write_byte(0xFF);
    }
    
    while(1);
    
    return 0;
}
Last edited by dan18374 on Wed Dec 21, 2016 2:33 pm, edited 1 time in total.
tsvoipio
Posts: 53
Joined: Wed Aug 19, 2015 9:44 pm

Re: Connect LCD-1x9 to at91sam7s256

Wed Dec 14, 2016 7:38 pm

dan18374 wrote:Hello everyone. I am new to sam7 and ARM in general. I want to connect LCD-1x9(Olimex LCD-MOD-1x9) to at91sam7s256(Olimex board SAM7-P256). Does anyone have same example projects or information how to connect LCD with TWI? Thank you!
What is the problem? There are instructions for both units on Olimex website. There is an UEXT connector on the processor card, and the display will connect to it.

There are also example pieces of code on the Olimex site.
dan18374
Posts: 2
Joined: Wed Dec 14, 2016 1:54 pm

Re: Connect LCD-1x9 to at91sam7s256

Wed Dec 14, 2016 7:56 pm

tsvoipio wrote:
dan18374 wrote:Hello everyone. I am new to sam7 and ARM in general. I want to connect LCD-1x9(Olimex LCD-MOD-1x9) to at91sam7s256(Olimex board SAM7-P256). Does anyone have same example projects or information how to connect LCD with TWI? Thank you!
What is the problem? There are instructions for both units on Olimex website. There is an UEXT connector on the processor card, and the display will connect to it.

There are also example pieces of code on the Olimex site.
Thank you for reply!
I tried to rewrite the code (LCD driver which I found on Olimex site), because it is for Olimexino, but I failed, the code does not work at all. :(
Maybe you have examples for ARM7?

Return to “SAM7 ARM7TDMI MCU”

Who is online

Users browsing this forum: No registered users and 2 guests