eeprom

Firmware/software/electronics/mechanics
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: eeprom

Post by tobias »

Well I think you found a typo is ST CPAL lib. The pin source should match the pin so it should be GPIO_PinSource8

Code: Select all

/*----------- I2C1 Device -----------*/
  
#define CPAL_I2C1_SCL_GPIO_PORT         GPIOB       
#define CPAL_I2C1_SCL_GPIO_CLK          RCC_AHB1Periph_GPIOB 
#define CPAL_I2C1_SCL_GPIO_PIN          GPIO_Pin_8
#define CPAL_I2C1_SCL_GPIO_PINSOURCE    GPIO_PinSource8
  
#define CPAL_I2C1_SDA_GPIO_PORT         GPIOB       
#define CPAL_I2C1_SDA_GPIO_CLK          RCC_AHB1Periph_GPIOB 
#define CPAL_I2C1_SDA_GPIO_PIN          GPIO_Pin_7
#define CPAL_I2C1_SDA_GPIO_PINSOURCE    GPIO_PinSource7
The pull-up should be connected to VCC somewhere along the SCL line. You can do it on the expansion board if that is easiest.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: eeprom

Post by Che. »

When I assign
Pin 8 to Source 8,
my Crazyflie wont start up properly.

When switching it back to
Pin 8 to Source 7, (as described in the table)
the Crazyflie starts up. But i wont get a reading.

NAMELY THIS IS MY READING:
B8 3A BE BE BE BE BE BE BE BE BE BE BE BE BE BE
Status 5


That maybe another problem when calling the bitcraze i2c-functions.

Is my approach the right one?
1.) initialize I2C1 device

Code: Select all

i2cdevInit(I2C1_DEV);
2.) perform signal acquisition (LIDAR2 Internal)

Code: Select all

i2cdevWriteByte(I2C1_DEV, 0x62, 0x00, 0x04);
Where 0x62 is the adress of the LiDAR...

3.) xTaskCreate my polling-task

4.) vTaskDelayUntil in polling task to make sure i wont overpoll anything

5.) Read byte

Code: Select all

i2cdevReadByte(I2C1, 0x62, 0x10, pData);
6.) Console Printing

Code: Select all

DEBUG_PRINT("pData:                %i\n", *pData);
tobias wrote:The pull-up should be connected to VCC somewhere along the SCL line. You can do it on the expansion board if that is easiest.
You mean soldering a resistor between SCL-pin and VCC?
How much ohms do i need there?
Sorry for those noobish questions.

Greets,
Che
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: eeprom

Post by tobias »

How much ohms do i need there?
4.7kOhm should be fine but anything from 2k - 10k probably works.
When I assign Pin 8 to Source 8, my Crazyflie wont start up properly.
Have you tries disabling the eeprom i2c reading? To me using pin source 7 on pin 8 is wrong. You can check the datasheet to confirm.
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: eeprom

Post by Che. »

Hi,

soldering of the resistor and disabling the configblock initialisation did the trick.

The Problem now is that i get the NACK-Error (0x400) from my I2CDEV. I really don't know how to handle this error.

CPAL_I2C_IsDeviceReady() gives me positive feedback.

but when calling i2cdevReadByte() i get the above error (CPAL_I2C_ERR_AF).

Do you have suggestions? I read in the cpal_i2c.h, the following:

Code: Select all

A transmitter which receives a NACK must reset the communication:
                                          - If Slave: lines are released by hardware.
                                          - If Master: a Stop or repeated Start condition must be generated 
                                            by software.
                                                 
                                         Software Clearing sequence for the ARLO bit:
                                         1. Writing '0' to this bit */        
Do you have a suggestion how to solve this? Its very confusing to me, as I need to constantly jump between all levels of the system.

Thanks for any hints!
Greets, Che
atomicdog
Expert
Posts: 105
Joined: Tue Mar 12, 2013 2:50 am
Location: San Diego

Re: eeprom

Post by atomicdog »

Is the read during a setup/init of the I2C device or are you just testing if it works by doing a random read?

Some I2C devices need to be setup up properly before they respond, so if you just tried to read a random register it wouldn't respond.
6-DOF CF | wireless xbox 360 controller
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: eeprom

Post by Che. »

Hi atomicdog, thanks for your answer!
atomicdog wrote:Is the read during a setup/init of the I2C device or are you just testing if it works by doing a random read?
First, I initiate the I2C-Device in the STM32 chip with i2cdevInit(I2C1_DEV).
Then I test, if the device is ready with CPAL_I2C_IsDeviceReady(I2C1_DEV).
I start my Task and then
in the last step I try to read the status of the I2C-Peripheral by calling the function i2cdevReadByte(I2C1_DEV, LIDARLITE_ADDRESS, LIDARLITE_REG_STATUS2, pData).

(STATUS2 is not a typo here)
atomicdog wrote:Some I2C devices need to be setup up properly before they respond, so if you just tried to read a random register it wouldn't respond.
I read int the manual, that i need to write to some registers to get the actual distance measurement routine started. but first i wanted to check if i could read anything in the first place.
Trying to set up the registers to the writing mode result in the same error though.
atomicdog
Expert
Posts: 105
Joined: Tue Mar 12, 2013 2:50 am
Location: San Diego

Re: eeprom

Post by atomicdog »

I haven't worked with this code base in a long time but it looks like you're using two different I2C libraries to me. If you're using CPAL it seems like all the I2C function should start with CPAL_ ?
What is I2C1_DEV? Doing a quick look at the functions it doesn't seem to make sense to pass in I2C1_DEV to both i2cdevReadByte() and CPAL_ functions.

Posting more of your code will make it easier to see what you're doing.
6-DOF CF | wireless xbox 360 controller
Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: eeprom

Post by Che. »

There is an interface written by bitcraze on top of the CPAL, as far as i understand, which lets you access the i2c-device. But I think I haven't completly understood how this bitcraze-interface works. I mentioned earlier, that its a bit confusing to switch between those levels. I might post my complete code here, which I see i shouldve done much earlier anyway :D

I2C1_DEV is just a define by bitcraze for the &I2C1_DevStructure.

Code: Select all

#define DEBUG_MODULE "RANGE"
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"

#include "config.h"
#include "range.h"
#include "system.h"
#include "param.h"
#include "log.h"

#include "i2cdev.h"
#include "cpal_i2c.h"
#include "lidarlite.h"

#include "debug.h"
#include "eprintf.h"

#include "cpal.h"
#include "cpal_i2c.h"


#include "stm32fxxx.h"


/* Internal values exported by functions below. */

static uint16_t rangeDistance = 0;
uint8_t status = 0;

uint8_t *pData;
uint8_t data;

static void rangeTask(void* param)
{
	DEBUG_PRINT("Start of rangeTask()\n");
	uint32_t lastWakeTime;

	vTaskSetApplicationTaskTag(0, (void*)TASK_RANGE_ID_NBR);

	//Wait for the system to be fully stated to start stabilization loop
	//systemWaitStart();

	lastWakeTime = xTaskGetTickCount();
	while(1)
	{

		vTaskDelayUntil(&lastWakeTime, F2T(RANGE_TASK_FREQ));
		DEBUG_PRINT("rangeTask running\n");



		//RESET FPGA
		i2cdevWriteByte(I2C1_DEV, LIDARLITE_ADDRESS, 0x00, 0x00);

		//PERFORM SIGNAL ACQUISITION
		//I2C-Address of LIDAR: 0x62
		i2cdevWriteByte(I2C1_DEV, LIDARLITE_ADDRESS, 0x00, 0x04);


		i2cdevReadByte(I2C1_DEV, LIDARLITE_ADDRESS, LIDARLITE_REG_STATUS2, pData);
		data = (unsigned int)pData;
		if (data & LIDARLITE_STAT_BUSY) DEBUG_PRINT("busy \n");
		if (data & LIDARLITE_STAT_REF_OVER) DEBUG_PRINT("reference overflow \n");
		if (data & LIDARLITE_STAT_SIG_OVER) DEBUG_PRINT("signal overflow \n");
		if (data & LIDARLITE_STAT_PIN) DEBUG_PRINT("mode select pin \n");
		if (data & LIDARLITE_STAT_SECOND_PEAK) DEBUG_PRINT("second peak \n");
		if (data & LIDARLITE_STAT_TIME) DEBUG_PRINT("active between pairs \n");
		if (data & LIDARLITE_STAT_INVALID) DEBUG_PRINT("no signal \n");
		if (data & LIDARLITE_STAT_EYE) DEBUG_PRINT(" eye safety \n");
	}
}



void rangeInit(void)
{
	i2cdevInit(I2C1_DEV);

	if(CPAL_I2C_IsDeviceReady(I2C1_DEV) == CPAL_PASS){
		DEBUG_PRINT("I2C1_DEV ready for communication...\n");
	}

	else{
		DEBUG_PRINT("I2C1_DEV not ready..\n");
	}

	xTaskCreate(rangeTask, (const signed char * const)RANGE_TASK_NAME,
			RANGE_TASK_STACKSIZE, NULL, RANGE_TASK_PRI, NULL);
			
	DEBUG_PRINT("End of rangeInit()\n");
}

uint32_t rangeGetDistance(void)
{
	return rangeDistance;
}

Che.
Member
Posts: 62
Joined: Tue Jul 28, 2015 1:47 pm
Location: Germany

Re: eeprom

Post by Che. »

I think the problem may be, that the CPAL doesn't send any Stop-Conditions after reading, which doesn't work with the sensor.
Post Reply