LPCXpresso LPC1769 board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCXpresso LPC1769 board

577 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fumio yoshizawa on Mon Oct 19 02:08:17 MST 2015
Hello,

I try to use I2C-E2PROM (24LC64) on LPCXpresso LPC1769 board .
I success read and write 24LC64 by NXP_LPCXpresso 1769_MCB1700_2011-02-11.zip
This library use CMSISv2_LCP17xx. Another sample zip file use CMSISv2p00_LCP17xx.
I want to read and write to 24LC64 by  CMSISv2p00_LCP17xx library. Is this example exist?
0 Kudos
Reply
7 Replies

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fumio yoshizawa on Thu Oct 29 01:24:58 MST 2015
Hello, some advice for me.

I try many times to use " I2C_MasterTransferData" in  library CMSISv2p00_LPC17xx.
I always get data "0xff". But the device (24LC64) different data include.I can get right data
another program.(not use  " I2C_MasterTransferData"  function.)
My read from eeprom simple code as follow.

Name        : TEST_EEPROM.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===================================================================
*/

#include "lpc17xx_i2c.h"
#include "lpc17xx_libcfg.h"
#include "lpc17xx_pinsel.h"
#include "i2c.h"

#define BUFFER_SIZE0x10
/** Own Slave address in Slave I2C device */
#define I2CDEV_S_ADDR(0xA0 >> 1)   // 24LC64 EEPROM

uint8_t Master_Buf[BUFFER_SIZE];
uint8_t master_test[5];
void Buffer_Init(uint8_t type);
static void eepromDelay(void);

__IO FlagStatus complete;                 // mbed sample

void I2C1_IRQHandler(void){
    // just call std int handler
    I2C_MasterHandler(LPC_I2C1);
    if (I2C_MasterTransferComplete(LPC_I2C1)){
        complete = SET;
    }
}

int main(void) {

__IO FlagStatus exitflag;
PINSEL_CFG_Type PinCfg;
I2C_M_SETUP_Type transferMCfg;
uint32_t tempp;
uint8_t *pdat;
    volatile static int i = 0 ;

    /* Disable I2C1 interrupt */
    NVIC_DisableIRQ(I2C1_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(I2C1_IRQn, ((0x01<<3)|0x01));

    //  Init I2C pin connect
// P0.19   P0.20 SDA1  SCL1
PinCfg.OpenDrain = 0;            // PINSEL_PINMODE_OPENDRAIN;
PinCfg.Pinmode = 0;              // PINSEL_PINMODE_PULLUP;
PinCfg.Funcnum = 3;
PinCfg.Pinnum = 19;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 20;
PINSEL_ConfigPin(&PinCfg);

// Initialize I2C peripheral
I2C_Init(LPC_I2C1, 1000);        //LPC_I2C1   100000 -> 1000
I2C_Cmd(LPC_I2C1, I2C_MASTER_MODE, ENABLE);      //
LPC_I2C1->I2CONSET = I2CONSET_I2EN;

//  read slave device
complete = RESET;
transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;   //24LC64 EEPROM address
transferMCfg.tx_data = NULL ;
transferMCfg.tx_length = 0;
transferMCfg.rx_data = Master_Buf;
transferMCfg.rx_length = 5;
transferMCfg.retransmissions_max = 3;
if(I2C_MasterTransferData(LPC_I2C1, &transferMCfg,  I2C_TRANSFER_INTERRUPT) == SUCCESS){
printf("read success\n\r");        
}                                          
    else {
    printf("read fail\n\r");
    }
while (complete == RESET);

for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){
printf("data1 = %x\n",Master_Buf[tempp]);
}

I2C_DeInit(LPC_I2C1);
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
}
0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Superfred on Wed Oct 21 00:27:24 MST 2015
Sorry, I don't have the time to check you code.
My code works with CMSISv2p00_LPC17xx, so try it or not, your choice.
0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fumio yoshizawa on Tue Oct 20 18:18:10 MST 2015
Thank you kindness.

I look at your source code. I understand and I also success similar way.
I want to use mouse device so I prefer library  CMSISv200_LCP17xx rather than CMSISv2_LPC17xx. So I want to read and write EEPROM use of  CMSISv200_LPC17xx.
I think the wrong part as this.
I hope "read success" and get data. But I get always "read fail".
I don't know real meaning of this code.
transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
transferMCfg.tx_data = NULL ;
transferMCfg.tx_length = 0;
transferMCfg.rx_data = Master_Buf;
transferMCfg.rx_length = sizeof(Master_Buf);
transferMCfg.retransmissions_max = 3;
if(I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING) == SUCCESS){
printf("read success\n\r");
}
    else {
    printf("read fail\n\r");
    }

0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Superfred on Tue Oct 20 07:54:11 MST 2015
Hello,
I am using the library in the attachment.

To write 32 bytes to the eeprom:
#define MC24LC64_ADDR 0xa0
I2CWriteLength[PORT_USED] = 35;
I2CReadLength[PORT_USED] = 0;
I2CMasterBuffer[PORT_USED][0] = MC24LC64_ADDR;
I2CMasterBuffer[PORT_USED][2] = addLsb; /* EEPROM memory address LSB */
I2CMasterBuffer[PORT_USED][1] = addMsb; /* EEPROM memory address MSB */
I2CMasterBuffer[PORT_USED][3] = ???;//first databyte
I2CMasterBuffer[PORT_USED][3] = ???;//next databyte
.........
I2CMasterBuffer[PORT_USED][35] = ???;//last databyte
I2CEngine();
...

To read 32 byte:
I2CWriteLength[PORT_USED] = 3;
I2CReadLength[PORT_USED] = 32;
I2CMasterBuffer[PORT_USED][0] = MC24LC64_ADDR;
I2CMasterBuffer[PORT_USED][2] = addLsb; /* EEPROM memory address LSB */
I2CMasterBuffer[PORT_USED][1] = addMsb; /* EEPROM memory address MSB */
I2CEngine();
...
//I2CSlaveBuffer: 32 bytes from EEPROM


0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fumio yoshizawa on Mon Oct 19 21:29:16 MST 2015
Sorry I took mistake.

// P0.19   P0.20 SDA  SCL
PinCfg.Funcnum = 3;
PinCfg.Pinnum = 19;   <<-------------
PinCfg.Portnum = 0;   <<--------------
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 20;
PINSEL_ConfigPin(&PinCfg);
0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fumio yoshizawa on Mon Oct 19 21:23:26 MST 2015
Thank you for reply.

My code as follow.
I can't read and write. Please advice for me.

#include "lpc17xx_i2c.h"
#include "lpc17xx_libcfg.h"
#include "lpc17xx_pinsel.h"

/************************** PRIVATE DEFINITIONS *************************/
/** Used I2C device as slave definition */
#define USEDI2CDEV_M1   //

/** Own Slave address in Slave I2C device */
#define I2CDEV_S_ADDR(0xA0)   // 24LC64 EEPROM

/** Max buffer length */
#define BUFFER_SIZE0x10
#define I2CDEV_M LPC_I2C1

static int I2CRead(uint8_t addr, uint8_t* buf, uint32_t len);
static int I2CWrite(uint8_t addr, uint8_t* buf, uint32_t len);

/** These global variables below used in interrupt mode - Slave device ----------------*/
uint8_t Master_Buf[BUFFER_SIZE];
uint8_t master_test[2];

void Buffer_Init(uint8_t type);

/*-------------------------MAIN FUNCTION------------------------------*/
int main(void)
{
PINSEL_CFG_Type PinCfg;
I2C_M_SETUP_Type transferMCfg;
uint32_t tempp;
uint8_t *pdat;

/* I2C block ------------------------------------------------------------------- */
/*
* Init I2C pin connect
*/
PinCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;

// P0.19   P0.20 SDA  SCL
PinCfg.Funcnum = 3;
PinCfg.Pinnum = 0;
PinCfg.Portnum = 19;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 20;
PINSEL_ConfigPin(&PinCfg);

// Initialize Slave I2C peripheral
I2C_Init(I2CDEV_M, 100000);        //I2CDEV_M = LPC_I2C1

I2C_Cmd(I2CDEV_M, I2C_MASTER_MODE, ENABLE);      //

/* Initialize buffer */
Buffer_Init(0);

/*
       I2CRead(I2CDEV_S_ADDR, pdat,2);

master_test[0] = 0xAA;
master_test[1] = 0x55;

I2CWrite(I2CDEV_S_ADDR, master_test, 2);

I2CRead(I2CDEV_S_ADDR, pdat,2);
printf("data = %x\n",pdat);
printf("data = %x\n",pdat++);
*/
// Start I2C slave device first
transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
transferMCfg.tx_data = NULL ;
transferMCfg.tx_length = 0;
transferMCfg.rx_data = Master_Buf;
transferMCfg.rx_length = sizeof(Master_Buf);
transferMCfg.retransmissions_max = 3;
if(I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING) == SUCCESS){
printf("read success\n\r");
}
    else {
    printf("read fail\n\r");
    }

pdat = Master_Buf;     //

for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){
printf("data = %x\n",pdat++);
}

// Transmit and receive --------------------------------------------------------
// Initialize buffer
Buffer_Init(0);
master_test[0] = 0xAA;
master_test[1] = 0x55;

// Start I2C slave device first
transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
transferMCfg.tx_data = master_test ;
transferMCfg.tx_length = sizeof(master_test);
transferMCfg.rx_data = Master_Buf;
transferMCfg.rx_length = sizeof(Master_Buf);
transferMCfg.retransmissions_max = 3;
if(I2C_MasterTransferData(I2CDEV_M, &transferMCfg, I2C_TRANSFER_POLLING)== SUCCESS){
printf("write success\n\r");
}
    else {
    printf("write fail\n\r");
    }
pdat = Master_Buf;
for (tempp = 0; tempp < sizeof(Master_Buf); tempp++){
printf("data = %x\n",pdat++);
}

I2C_DeInit(I2CDEV_M);
    // Loop forever
    while(1);
}

/*********************************************************************//**
* @briefInitialize buffer
* @param[in]type:
* - 0: Initialize Master_Buf with increment value from 0
* Fill all member in Slave_Buf with 0
* - 1: Initialize Slave_Buf with increment value from 0
* Fill all member in Master_Buf with 0
* @return None
**********************************************************************/
void Buffer_Init(uint8_t type)
{
uint8_t i;

if (type)
{
for (i = 0; i < BUFFER_SIZE; i++) {
Master_Buf = i;
}
}
else
{
for (i = 0; i < BUFFER_SIZE; i++) {
Master_Buf = 0;
}
}
}

static int I2CRead(uint8_t addr, uint8_t* buf, uint32_t len)
{
I2C_M_SETUP_Type rxsetup;
rxsetup.sl_addr7bit = addr;
rxsetup.tx_data = NULL; // Get address to read at writing address
rxsetup.tx_length = 0;
rxsetup.rx_data = buf;
rxsetup.rx_length = len;
rxsetup.retransmissions_max = 3;
if (I2C_MasterTransferData(I2CDEV_M, &rxsetup, I2C_TRANSFER_POLLING) == SUCCESS){
printf("read success\n\r");
return (0);
} else {
printf("read fail\n\r");
return (-1);
}
}

static int I2CWrite(uint8_t addr, uint8_t* buf, uint32_t len)
{
I2C_M_SETUP_Type txsetup;
txsetup.sl_addr7bit = addr;
txsetup.tx_data = buf;
txsetup.tx_length = len;
txsetup.rx_data = NULL;
txsetup.rx_length = 0;
txsetup.retransmissions_max = 3;
if (I2C_MasterTransferData(I2CDEV_M, &txsetup, I2C_TRANSFER_POLLING) == SUCCESS){
printf("write success\n\r");
return (0);
} else {
printf("write fail\n\r");
return (-1);
}
}


0 Kudos
Reply

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Superfred on Mon Oct 19 06:22:04 MST 2015
I use the MCB1700 I2C example with the CMSISv2p00_LCP17xx library, and as far as I remember evererything worked fine.
If you get errors please post them.

But maybe LpcOpen is the better choice for a new project....
0 Kudos
Reply