I2C Master Example Code With MCP4725

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

I2C Master Example Code With MCP4725

2,501 Views
rohit_alate
Contributor II

Hello Team,

I am trying to interface the MCP4725 Module with my S32K148_EVAL Board .for that I am using the ref for the I2C Master Example Code, in the configuration I updated the Device address for the DAC Module 0x60 but it is not able to send the data on the BUS,

Can anyone help me out here with what I am missing here?

Thanks in Advance,
Rohit 

0 Kudos
Reply
9 Replies

2,491 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

could you please share the connection you have? Do you have pull-ups on I2C lines?
Do you have any scope/analyzer screen of generated frames? Or nothing is seen?

BR, Petr

0 Kudos
Reply

2,440 Views
rohit_alate
Contributor II

hi @PetrS ,

NXP -> MCP4725
PTE1 -> SCL

PTC31 ->SDA

J3-13(V5_0) -> VCC

J3-16(GND)->GND

From MCP4725

Out --> +ve scope

Gnd -> -ve scope

No Pullups on I2C Line.

 

IMG-20211117-WA0000.jpgIMG-20211117-WA0001.jpgIMG-20211117-WA0002.jpg

 

0 Kudos
Reply

2,435 Views
rohit_alate
Contributor II

Hello @PetrS ,

I am able to get the Analog data on the scope now, so DAC Interfacing is done.
But a new issue that I am facing is like when I created a different test project and configure the i2c then it will be working fine.

 

but I have one existing project in that I need to add this so when I am adding the i2c module and the same logic to update the DAC it is going into the Default ISR,

so what could be the reason so I can check on that?

0 Kudos
Reply

2,483 Views
rohit_alate
Contributor II

Hello @PetrS ,

I am able to connect the NXPS32K148-EVAL board with MCP4725(12 bit DAC Module).and i am getting analog data as per my inputs.

But the same thing when i try in a loop then it is not giving the analog values based on the input values,

Code : 

void setVoltage(uint16_t output)
{

uint8_t packet[3];


packet[0] = MCP4725_CMD_WRITEDAC;
packet[1] = output / 16; // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
packet[2] = (output % 16) << 4; // Lower data bits (D3.D2.D1.D0.x.x.x.x)

/* Send a packet of data to the bus slave */
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, packet, 3, true, OSIF_WAIT_FOREVER);
}

void delay(int value)
{
while(value--)
{

}
}

int main()

{

.....

for (int i = 0 ; i < 4096 ; i++)
{

setVoltage(1000);
delay(100000);
}

......
}

 

 

it will be really helpful if you help me in this,

Thanks,
Rohit

Tags (1)
0 Kudos
Reply

2,474 Views
rohit_alate
Contributor II

Hello @PetrS ,

its my mistake i assumed it is working but it is still not working ,
PFA :
I2C Configuration :
lpi2c_master_user_config_t lpi2c1_MasterConfig0 = {
.slaveAddress = 98U,
.is10bitAddr = false,
.operatingMode = LPI2C_STANDARD_MODE,
.baudRate = 100000U,
.transferType = LPI2C_USING_INTERRUPTS,
.dmaChannel = 0U,
.masterCallback = NULL,
.callbackParam = NULL,
};

 

main.c file :
main()

{

LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0, &lpi2c1MasterState);

status_t status;
//status = setVoltage(4095);
while(1)
{

status = setVoltage(10);

}

}

it is not able to set the voltage.

0 Kudos
Reply

2,465 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

please share what is outputted on I2C lines. Does it correspond to the slave device protocol?
What is the value of MCP4725_CMD_WRITEDAC?

BR, Petr

0 Kudos
Reply

2,462 Views
rohit_alate
Contributor II

Hello @PetrS ,

The Values :

#define MCP4725_I2CADDR_DEFAULT (0x62) ///< Default i2c address
#define MCP4725_CMD_WRITEDAC (0x40) ///< Writes data to the DAC
#define MCP4725_CMD_WRITEDACEEPROM (0x60) ///< Writes data to the DAC and the EEPROM (persisting the assigned value after reset)

and on pin it is giving the constant 2.57 v as DAC Output to any input Value.

0 Kudos
Reply

2,455 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

does the DAC acknowledge any byte? You configured slave address 0x62 so you have A0 pin tied to VDD, it that right? Do you really have device with A2:A1 addresses 0:0. As per datasheet this is default factory config, but can be also different, see package marking information.

BR, Petr

0 Kudos
Reply

2,445 Views
rohit_alate
Contributor II

Hi @PetrS,

yes, the address of the slave device is 0x60 I updated that one with fast mode configuration,
but still, it is not able to generate the analog signal,

I try to check the DAC module with interfacing with Arduino board and it is working fine with the same logic and all but at NXP side what I am missing not able to get,

PFA for the Zip of the project,

thanks for your quick responses,

Regards,
Rohit

 

0 Kudos
Reply