This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Take a look at my interface with LM4970

Other Parts Discussed in Thread: LM4970

 Hello,

Do i have to send the address of the LM4970 every time i send it one byte of data, for example, i want to program all of its register, meaning i have to have separate transaction everytime i want to write to it.

Second question, is there a specific order that i have to send the data in, meaning, does it load each register in order, i dont know if my question makes sense.

I have attached my code, can you guys take a look and comment?

1754.main (1).c
#include "p24hxxxx.h"
#include "p24HJ64GP502.h"	
#include <stdio.h>
#include <stdlib.h>	
#include "i2c.h"
	 

#ifdef __PIC24HJ64GP502__
_FOSCSEL(FNOSC_FRC);	 // set oscillator mode for FRC ~ 8 Mhz
_FOSC(FCKSM_CSDCMD & OSCIOFNC_ON & POSCMD_NONE);	// use OSCIO pin for RA3
_FWDT(FWDTEN_OFF);	 // turn off watchdog
#elif defined(__dsPIC33FJ64MC802__)
_FOSCSEL(FNOSC_FRC);	
_FOSC(FCKSM_CSDCMD & OSCIOFNC_ON & POSCMD_NONE);
_FWDT(FWDTEN_OFF);	
#endif
#define LM4970_ADDR_0 0x7A // first 7 bits of address 0 (ADR = LOW)
#define LM4970_ADDR_1 0x7B // first 7 bits of address 1 (ADR = HIGH)
#define LM4970_MODE_NORM 0x00 // power up, normal I2C, no random
#define LM4970_MODE_RAND 0x04 // power up, normal I2C, random
#define LM4970_FREQ 0x50 // 6.3kHz High Pass / 15kHz PWM
#define LM4970_PATT_AUDIO 0x60 // pattern gen by audio input
#define LM4970_PATT_I2C 0x61 // pattern gen by I2C - all off
#define LM4970_CURR 0xAA // 1x current (21mA)on LED 1-3
#define LM4970_GAIN 0xEA // gain = 10dB / midband = medium
#define I2C_ON 0xFFFF
#define I2C_START_EN               0xFFFF



void i2c_init();
void i2c_send(int x, int y);

int main ()
{
OSCCON = 0x0000;    
OSCCONbits.COSC=1;                                     // FRC osc with PLL
OSCCONbits.NOSC=1;
OSCCONbits.IOLOCK=1;                                   //peripheral pins lock
CLKDIVbits.PLLPOST=1;                                    //N2=4
CLKDIVbits.PLLPRE=6;                                      //N1=8
CLKDIVbits.DOZE =1;                                        // doze 2
CLKDIVbits.DOZEN=1;
PLLFBDbits.PLLDIV=171;                                    // M=173
OSCTUN   = 0x0000;
RCONbits.SWDTEN     = 0;                         //Disable Watch Dog Timer
AD1PCFGL=0xFFFF;
PORTBbits.RB8=0;                               //clock on oin B8
PORTBbits.RB9=0;                                //data on pin B9 
                                  		

i2c_init(); // start I2C module

i2c_send(LM4970_ADDR_0,LM4970_MODE_NORM); // power up, normal I2C, no random

i2c_send(LM4970_ADDR_0,LM4970_FREQ); // 6.3kHz High Pass / 15kHz PWM

i2c_send(LM4970_ADDR_0,LM4970_PATT_AUDIO); // // pattern gen by audio input

i2c_send(LM4970_ADDR_0,LM4970_CURR); // 1x current (21mA)on LED 1-3

i2c_send(LM4970_ADDR_0,LM4970_GAIN); // gain = 10dB / midband = medium


I2C1CONbits.I2CEN = 0;  // stop I2C module



}

void i2c_init()
{
   I2C1BRG = 197;
   I2C1CONbits.I2CEN = 0;    // Disable I2C Mode
   I2C1CONbits.DISSLW = 1;    // Disable slew rate control
   IFS1bits.MI2C1IF = 0;    // Clear Interrupt
   I2C1CONbits.I2CEN = 1;    // Enable I2C Mode
   I2C1CONbits.RCEN = 0;
   I2C1STATbits.IWCOL = 0; // no collision
   I2C1STATbits.BCL = 0; // no collision on master bus
}

void i2c_send(int x, int y)
{
	I2C1CONbits.SEN = 1;  // start condition enable
	while(I2C1CONbits.SEN);

	I2C1TRN = x;             // place address into send register
	while(I2C1STATbits.TBF); 
    while(I2C1STATbits.TRSTAT);   
    while(I2C1STATbits.ACKSTAT); 

	I2C1TRN = y;               //place data into send register
	while(I2C1STATbits.TBF); 
    while(I2C1STATbits.TRSTAT);   
    while(I2C1STATbits.ACKSTAT);

	I2C1CONbits.PEN = 1;      // stop condition enable

	
	
}


 

can i program the LM4970 in that manner that i have in the code?

  • Hi, Anh,

    The I2C requirements are listed at the bottom of page 10 of the data sheet, in the section titled, "I2C COMPATIBLE INTERFACE"

    -d2

  • What i am confused is what it says in that section: repeat the previous two steps until all bytes are send,

    im confused, because do i need to resend the address of the LM4970 along with another byte of data?

    see if this makes sense and correct to you:

    I2c start condition -->address send----> byte send---> byte send---> byte send---> stop condition.

    the above only has the address sent over the wire one time, is that correct?

    another question: does the lm4970 program its register in a specific order : (e.g Mode select, req select, pattern select, current select, gain select, in that order)

    meaning if i send a stop condition after sending the mode select byte, then when i restart, it will program the mode select again, right?

  • Was this issue ever resolved? I am having trouble sending several data transmissions at once also.

    My data transmission sequence looks like this:

    I2c start condition -->address send----> byte send---> byte send---> byte send---> byte send---> ........ ----> stop condition.

    With the ....... representing many bytes. 

    This will only update the register once. 

    The guys on my team seem to think the updates are happening too quickly. 

  • Hi, Mark,

    I'm not sure... Unfortunately, this is a really old part, and we don't have any EVMs laying about that I can easily test for you... Apologize for that.

    This seems like a strange way to do I2C to me, but it might just be a different way of doing things (this was developed by NSC, not TI).

    I don't understand your comment, "This will only update the register once."

    Can you expand on that comment?

    If you scope the SCL/SDA, do they look ok? What speed are you running your bus at?

    -d2

  • Hi Don,

    I was doing some forum diving today and happened upon this thread. It's not my exact problem, but I thought the solution would help me in my own application.

    I'm actually using a completely different chip. It seems as though I should start a new thread with a new question.

    Cheers,

    Mark

  • Hi, Mark,

    No problem! If it's a TI chip, post away! If it's a competitor's chip, please buy one of ours!!! We have EVERYTHING!!! :)

    -d2