10 years, 7 months ago.

Issue with FRDM-KL46Z I2C

I am experimenting with DS1621 using library written by 'D Brono' with Mbed 1768 and FRDM-KL46Z By changing the I2C pins accordingly to each board, using the same code:

#include "mbed.h"
#include "ds1621.h"

#define DS1621_ADDR 0     // I2c DS1621 address is 0x04

Serial pc(USBTX, USBRX);  // Declare usb (see screen /dev/ttyUSB0 on linux)
I2C    i2c(p9, p10);     // Declare I2C for LPC1768
//I2C    i2c(D7,D6);     // Declare I2C for FRDM-KL46Z
DS1621 ds(&i2c, DS1621_ADDR);  // Declare ds1621 throught i2c interface

int main() {
    i2c.frequency(5000); //5khz
    pc.printf("-----------------------\n\rMain\n\r");
    float temp = 0.0;
    ds.init(DS1621_ADDR);
    while (1) {
        temp = ds.read(DS1621_ADDR);
        pc.printf("Temperature=%3.1f C\n\r",temp);
        pc.printf("Temperature=%3.1f F\r\n\n",temp *9/5 + 32 );
        wait(2.0);
    }
}

It works correctly with LPC1768 but not with FRDM-KL46Z. I have tried A4/5, D7/6 and D14/15, still didn't work. FRDM board kept giving me 0C/32F.

Could someone help/suggest ? Many thanks. samira

I see you are using 5kHz. Can you test the same freq with on board accelerometer?

posted by Martin Kojtal 18 May 2014

I will give it a try and will report back the result. Thanks.

posted by samira samilan 18 May 2014

I use this code <<code>>

  1. include "mbed.h"
  2. include "MMA8451Q.h"
  1. define MMA8451_I2C_ADDRESS (0x1d<<1) Serial pc ( D1, D0);

int main(void) {

MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); PwmOut rled(LED_RED); PwmOut gled(LED_GREEN); PwmOut bled(LED_BLUE);

while (true) { rled = 1.0 - abs(acc.getAccX()); gled = 1.0 - abs(acc.getAccY()); pc.printf( "X %0.2f \r\n", abs(acc.getAccX())); bled = 1.0 - abs(acc.getAccZ()); wait(0.5); } } <</code>

the led glows brighter when I move the board along the x or y axis.

posted by samira samilan 19 May 2014
Be the first to answer this question.