I2C Bit Banging with VS1010D for Reading sensor data

Using VSDSP legacy command line tools.
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

Hi!

I'm trying to develop a system with VS1010D where it will able to read sensor data through I2C communication. In VS1010D, it doesn't contains any I2C pin ; so I want to develop this I2C communication by using normal GPIO pins of VS1010D.

If there is any example of I2C bit banging please provide.

Thank you.
Hannu
VLSI Staff
Posts: 563
Joined: Mon 2016-05-30 11:54
Location: Finland
Contact:

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by Hannu »

The problem with I2C is the nature of it being open collector bus. Sometimes it matters and sometimes it doesn't. Speed is another issue often. Sometimes I2C has to be insane fast with high drive and sometimes it has to be slowed down. That's why all implementations are written for specific board and the software around the i2c implementation.

You need to write start condition, stop condition, ACK detect and then read and write functions. Also think about the error propagation if your slave device gives NACK and is it part of the protocol it communicates.

Pin low state can be done with GpioSetPin(pin, 0) and high GpioSetAsInput(pin). The I2C pull-up resistor pulls line to high when the pin is input. GpioReadPin(pin) can be used.

Not so easy to read i2c communication code can be found from ROM sources. It drives the I2C lines to IOVDD (Not compliant with I2C) It is used to boot from I2C flash using MOSI0 as SDA and SCLK0 as SCK. Easiest is to change the pins to some other GPIO1 pins, for example UART1 if it isn't used.
Files are i2cp2.c and .h
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

Hi Hannu!

Thanks for your replay. I got the I2C driver file i2cp2.c and .h for vs1005g but I need the driver for VS1010D and based on your suggestion I want use the UART1 pins as SDA and SCL.

Is there any I2C driver file for VS1010D?

Thank you!
Attachments
arch-i2cRead05-2017-06-05-18-29-test1.zip
(7 KiB) Downloaded 433 times
Hannu
VLSI Staff
Posts: 563
Joined: Mon 2016-05-30 11:54
Location: Finland
Contact:

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by Hannu »

The solution you attached is for VS1005.

Take the I2C files .c and .h, put to your VS1010 project, change the pins to the UART1 GPIO pins from .h file and build. Should work if your I2C bus doesn't need to be open collector bus.
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

Hi!
Thanks for the replay. According to your suggestion I had changed the above i2cp2.h GPIO pin to UART1 by following the VS1010 datasheet (page-37,38).
The Address has been changed but the data reading remain same. I had attached a color sensor SDA and SCL to RX,TX of VS1010 mini demo board accordingly.

Code: Select all

#include <vs1010c.h>

// I2C Pin Mappings: I2C pins are assumed to be in GPIO1.
#define SDA_PIN_GPIO1 10 /* SDA is GPIO1[10] (RX1) */
#define SCL_PIN_GPIO1 11 /* SCL is GPIO1[11] (TX1) */

Code: Select all

ioresult main(char *parameters) {
	u_int16 address = atoi(parameters);
	u_int16 data;
	//i2c_device_write_address = 0xFE10;
	//i2c_device_write_address = 0xFE1F;
	i2c_device_write_address = 0xa0;
	//address=i2c_device_write_address;
	//address=0x31;
	address=0xFE10; //RX1
	data = Eeprom2ReadByte(address);
	printf("Address: 0x%04x, Data: 0x%02x\n",address,data);

	return S_OK;
}
I have assumed that I need to develop the i2c bit-bang for reading the data. If I'll follow the below link then it will be possible to develop the bit-bang functionalities for VS1010? :?:
https://calcium3000.wordpress.com/2016 ... l-part-i/

I need your help to develop the i2c bit-bang functionalities for VS1010.

Thank you.
Hannu
VLSI Staff
Posts: 563
Joined: Mon 2016-05-30 11:54
Location: Finland
Contact:

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by Hannu »

Hi,

Do you call InitI2C() ? And with the correct device address it should return 1.

You already have the byte functions. And with them you can work the communication protocol of your sensor.

I2cPutOctetAndGetAck
I2cGetOctetAndNoack
I2cGetOctetAndAck

The Eeprom...() functions are intended for I2C eeproms and flashes.

In minidemoboard, you have TX1 in one test pad and RX1 available in some corner of RPI1 resistor array. It isn't the easiest board to interact with outside world.
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

Hi!
Thanks for the suggestion.
Hannu wrote: Mon 2021-08-23 10:31 Do you call InitI2C() ? And with the correct device address it should return 1.
I had tried with the InitI2C() but it always return 0 with address 0x31/0x32 (rx1/tx1) and address 0x2d/0x2c (rx0/tx0). [address taken from VS1010 datasheet]

Code: Select all

void readData(){
	u_int16 data;
	u_int16 address=0x31;//rx1
	
	i2c_device_write_address = 0xA0;
	
	//data = Eeprom2ReadByte(address);
	data = InitI2C(address);	
	printf("Address: 0x%04x, Data: 0x%02x\n\r",address,data);	
}

Code: Select all

void readData(){
	u_int16 data;
	u_int16 address=0x2d;//rx0
	
	i2c_device_write_address = 0xA0;
	
	//data = Eeprom2ReadByte(address);
	data = InitI2C(address);	
	printf("Address: 0x%04x, Data: 0x%02x\n\r",address,data);	
}
Both condition I had received 0 from InitI2C(address).
Now please suggest me what would be the address for "i2c_device_write_address" and "u_int16 address" for i2c communication on VS1010?

Thank you.
Hannu
VLSI Staff
Posts: 563
Joined: Mon 2016-05-30 11:54
Location: Finland
Contact:

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by Hannu »

InitI2C() takes the I2C device address. It can be found from your sensor's datasheet.
0x002c, 0x002d, 0x0031 and 0x0032 are totally different addresses. In those addresses in I-memory exist interrupt vectors.

This code scans all devices:

Code: Select all

u_int16 deviceAddr;
for(deviceAddr = 0; deviceAddr < 256; deviceAddr++) {
  u_int16 ret = InitI2C(deviceAddr);
  printf("device %u: %s\n", ret?"OK":"NAK");
}
If you have connected sensor to right pins and configured the I2C code to use those, it should work. Your sensor should need four wires, GND, IOVDD, SDA, and SCK. Previously you had UART1 configured correctly. If you haven't change it, you get SDA from RX1, and SCK from TX1.
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

Hi Hannu!

I had tried with your last shared code but it doesn't seems working to me. I had connected the logic analyzer with the RX and TX pin to see the SCK and SDA responses but the data are NAK as I get flat line in the SDA channel. Now I'm trying to get the VS developer board where I need your suggestion.

I'm working with VS1010 mini demo board. Now, Can you please suggest me a developer board which will be overcome the limitation of VS1010 Mini demo board but the processor will be same as VS1010?

Focus Area: i2c communication, NAND flash R/W option.

Thank You!
avizet
Senior User
Posts: 28
Joined: Tue 2021-06-29 11:25

Re: I2C Bit Banging with VS1010D for Reading sensor data

Post by avizet »

HI!

Which development board will be more flexible for testing purpose for developing i2c communication? Currently, I'm using VS1010 mini demo board.

Thank You!
Post Reply