CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Renesas FS2012 + PIC16F877A I2C Issues

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
welbertdeoliveira



Joined: 29 Aug 2022
Posts: 1

View user's profile Send private message Send e-mail

Renesas FS2012 + PIC16F877A I2C Issues
PostPosted: Mon Aug 29, 2022 11:32 am     Reply with quote

Good afternoon.

I'm facing some problems for interface a Renesas FS2012 gas flow sensor with a PIC16F877A. The procedure for configuring the communication, based on the documentation is:

"To obtain data from the sensor, send START bit, slave address (0x07) and read bit (READ) to FS2012 and then read the two bytes of sensor data." (https://www.renesas.com/us/en/document/apn/fs2012-sample-application?language=en, page 10, "3.2 Sensor Functions").

I'm trying to configure the interface and obtain the MSB and LSB, and print on a 16x2 LCD. But, it's only possible to see FFh in both registers.

I can see the I2C protocol working by an oscilloscope.

Could anyone help me?

Best regards.
Code:

/*
-------------------------------------------------------------------------------------
   Renesas FS2012 Gas Flow Sensor + display LCD 16x2
   Biblioteca nativa do CCS C
   Modo 4 bits
   I/O no PortD

   Conexoes fĂ­sicas do LCD na PortD

   lcd_enable_pin    pin_B5
   lcd_rs_pin        pin_B4
   lcd_rw_pin        pin_B3
   lcd_data4         pin_D4
   lcd_data5         pin_D5
   lcd_data6         pin_D6
   lcd_data7         pin_D7

-------------------------------------------------------------------------------------
*/

#include    <16F877A.h>
#use        delay(clock = 4000000)
#use        I2C(master, fast = 100000, sda = pin_C4, scl = pin_C3)
#fuses      XT, NOWDT, PUT, NOLVP

#define   lcd_rs_pin        pin_B5
#define   lcd_rw_pin        pin_B4
#define   lcd_enable_pin    pin_B3
#define   lcd_data4         pin_D4
#define   lcd_data5         pin_D5
#define   lcd_data6         pin_D6
#define   lcd_data7         pin_D7
#define   sensor_address    0x07


#include    <lcd.c>

unsigned int8 dado_H, dado_L = 0;

void main()
{

   // Habilita o LCD e imprime mensagens iniciais
   lcd_init();
   lcd_putc('\f');
   delay_ms(100);
         
  while(true)
   {
   
   i2c_start();
   i2c_write(sensor_address);
   i2c_write(1);
   i2c_start();
   i2c_write(sensor_address);
   dado_H = i2c_read(1);
   dado_L = i2c_read(0);
   i2c_stop();
   
   lcd_gotoxy(1,1);
   lcd_putc("MSB: ");
   lcd_gotoxy(6,1);
   printf(lcd_putc, "%X", dado_H);
   lcd_gotoxy(1,2);
   lcd_putc("LSB: ");
   lcd_gotoxy(6,2);
   printf(lcd_putc, "%X", dado_L);

   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 29, 2022 3:17 pm     Reply with quote

The FS2012 data sheet lists 0x07 as the slave address. That's in 7-bit format.
However, CCS i2c routines use 8-bit format, so double that to 0x0E.
Then we get:

i2c read address: 0x0E
i2c write address: 0x0F

--------------------------------------
Also, your i2c read data routine needs to be changed to this:
Quote:
i2c_start();
i2c_write(SENSOR_WRITE_ADDRESS); // 0x0F
i2c_write(1);
i2c_start();
i2c_write(SENSOR_READ_ADDRESS); // 0x0E
dado_H = i2c_read(1);
dado_L = i2c_read(0);
i2c_stop();
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Wed Aug 31, 2022 1:24 am     Reply with quote

It is slightly worrying that the device is using a reserved address.

In 7bit addresses 0 to 7, and 78 to 7F are legally reserved addresses.
Devices are not meant to use these. 7 is actually reserved as the speed
control address value.
The I2C valid 7bit device addresses are 8 to 77.
That a device is being sold that uses one of the reserved addresses, is
'scary'... Sad
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group