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

BME280 debug output help / now error on PIC24
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

BME280 debug output help / now error on PIC24
PostPosted: Sun Dec 20, 2020 5:35 am     Reply with quote

I am dealing with the bme280 driver and would like to enable the debug output.
But i am a bit confused. I can not get the macro debug_bme280 to output anything to my stream.

I have seen an example here in the forum that I just setup an own output
to my ordinary stream DEBUG that I use on Uart3.
Code:

 void debug_putc(int8 c)
 {
   fputc(c, DEBUG);
 }

but nothing comes out from the
Code:

debug_bme280(debug_putc,"xxx");

What have I missed ? Any more defines ??


Last edited by towpew on Sun Jan 03, 2021 6:08 am; edited 2 times in total
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 20, 2020 7:31 pm     Reply with quote

Now there are a few 'bme280 drivers' ont eh web, that's why I asked _which_ one.

If this bme280 driver is the CCS supplied one, contact CCS for support.
I don't have a recent version of the compiler....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 20, 2020 10:25 pm     Reply with quote

Post your PIC and post your #use rs232() line for the DEBUG stream.
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

PostPosted: Sun Dec 20, 2020 11:30 pm     Reply with quote

PCM programmer wrote:
Post your PIC and post your #use rs232() line for the DEBUG stream.


I have the latest bme280.c from CCS

MCU is
#include <24FJ256GB406.h>

Stream
#use rs232(UART3, baud=19200, stream=DEBUG) //DEBUG
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Dec 21, 2020 1:40 am     Reply with quote

So, have you tested just printing something to the DEBUG stream?.
It could be something silly like the UART output being only 3.3v, and not
being enough to talk to your receiving device. You need to test one thing
at a time. UART3 is a PPS device, so your #PIN_SELECT lines for this
should be shown. Also, what compiler version?.
Start by verifying you have got the UART device working correctly.
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

SOLVED
PostPosted: Mon Dec 21, 2020 9:54 am     Reply with quote

Solved with help from CCS R.

Had to enable macro with
Code:
#define debug_bme280 printf

and the function
Code:

void debug_putc(char c)
{
   fputc(c, DEBUG);
}

before the #include bme280.c

After that all debug pop up.

Ttelmah wrote:
So, have you tested just printing something to the DEBUG stream?.
It could be something silly like the UART output being only 3.3v, and not
being enough to talk to your receiving device. You need to test one thing
at a time. UART3 is a PPS device, so your #PIN_SELECT lines for this
should be shown. Also, what compiler version?.
Start by verifying you have got the UART device working correctly.

Yes I use the DEBUG for my other debug output. Works OK and UART3 is hw pins.
I have a USB to TTL 3V3 adapter on 19200 baud to Siow.

One question about macro how do they actually work here is macro debug_bme280 suppose to call the debug_putc function I have setup ?
Like a normal function call ?

I use ios so my debug stream calls with the debug << "hello".

One way could be to replace all debug_bme280 macro with the debug << instead.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Dec 21, 2020 11:55 am     Reply with quote

Macros are simple preprocessor substitutions. Almost basic text
substitutions, but just a little more capable. So where the macro is typed
the right hand side text is substituted before compilation.
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

Switch between two I2C bus with BME280 on
PostPosted: Fri Dec 25, 2020 11:24 am     Reply with quote

I ran up to another question here with my BME280 readings.

On the PIC24FJ256GB406 there are 3 I2C channels and I use
I2C1 for the bus of number of 6 BME280 switching the SDA line with multiplexer.

On I2C3 i have 1 another BME280 connected and now to the problem.

I would like to use the same driver for both these busses and the easiest way I thought about was to use the
Code:

 #use i2c(MASTER, SCL=PIN_E6, SDA=PIN_E7, STREAM=STREAM_I2C_BME280, NOINIT,FAST=BME280_I2C_BAUD)


This is to switch PINs to I2C3 and then when I want to go back to the I2C1 bus i use:
Code:

i2c(MASTER, SCL=PIN_BME280_SCL, SDA=PIN_BME280_SDA, STREAM=STREAM_I2C_BME280, NOINIT,FAST=BME280_I2C_BAUD)

When I run this code lines in runtime it does not work as I think ?

The program does not change the PIN, they are stuck on I2C1.

I should also say that the defines for the BME280 I2C pins is in the
beginning of the BME280.c driver as #defines.

Is the defines mandatory in any way and how can I change I2C bus in runtime ?

In the driver it talks about different streams to connect to different I2C addresses on the same bus ? It there a easy way to change stream in runtime ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Dec 25, 2020 12:16 pm     Reply with quote

Just change a variable defining the stream.

So have the first bus called STREAM_I2C_BME280, and the second
STREAM_I2C3_BME280

Then have a int16 variable 'called BME_i2c_stream. Use this variable for the
stream name in the function talking to the chip. When you want to talk to
I2C1, just set BME_i2c_stream=STREAM_I2C_BME280; Then when you
want to talk to the I2C3 stream just set
BME_i2c_stream=STREAM_I2C3_BME280;

The function will then talk to the new stream.
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

PostPosted: Sat Dec 26, 2020 3:33 am     Reply with quote

Ttelmah wrote:
Just change a variable defining the stream.

So have the first bus called STREAM_I2C_BME280, and the second
STREAM_I2C3_BME280

Then have a int16 variable 'called BME_i2c_stream. Use this variable for the
stream name in the function talking to the chip. When you want to talk to
I2C1, just set BME_i2c_stream=STREAM_I2C_BME280; Then when you
want to talk to the I2C3 stream just set
BME_i2c_stream=STREAM_I2C_BME280;

The function will then talk to the new stream.


Ok, I have setup another stream to I2C3 named:
Code:

#use i2c(MASTER, I2C3, FAST, stream=STREAM_I2C3_BME280)

then for I2C1 I have the one already defined in the driver with the
Code:

#use i2c(MASTER, SCL=PIN_BME280_SCL, SDA=PIN_BME280_SDA, STREAM=STREAM_I2C_BME280, NOINIT, FAST=BME280_I2C_BAUD)

If understand you right I then change all the stream names in the driver that actually talk to the chip.

For example the first read function use i2c_start(BME_i2c_stream) here I change the stream name to the new int16 BME_i2c_stream name.

But this give an error even if I use:
BME_i2c_stream=STREAM_I2C3_BME280

I got Error 130 Stream must be a constant in the valid range.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Dec 26, 2020 5:24 am     Reply with quote

OK. Let me show you how to switch streams:
Code:

typedef enum {I2C1=1,I2C2,I2C3,I2C4,I2C5} streamname;
#define M_I2C_write(n,x) i2c_write(bus##n,x)
#define M_I2C_start(n) i2c_start(bus##n)
#define M_I2C_stop(n) i2c_stop(bus##n)
#define M_I2C_read(n) i2c_stop(bus##n)

#use i2c(MASTER, I2C1, FAST, stream=bus1)
#use i2c(MASTER, I2C3, FAST, stream=bus2)
 
void i2c_test(int streamnum)
{
   //routine doing basic I/O on selected stream
   if (streamnum==1)
   {
      M_i2c_start(1);
      M_i2c_write(1,0xA0);
      M_i2c_write(1,0x10);
      M_i2c_stop(1);
   }
   else
   {
      M_i2c_start(2);
      M_i2c_write(2,0xA0);
      M_i2c_write(2,0x10);
      M_i2c_stop(2);
   } 
}

void main()
{
   int stream=1; //port1 first
   while(TRUE)
   {
      i2c_test(stream); //talk to port
      stream=stream+1; //switch stream
      if (stream>2)
         stream=1;
   }
}


The same function does it's I2C I/O to two different streams
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

BME280 error reading on PIC24
PostPosted: Sun Jan 03, 2021 6:03 am     Reply with quote

First thanks for the switch stream code Ttelmah.

I have another problem now and that is that the latest driver I have got from CCS is not working any good for my PIC24FJ256GB406.

I got mostly error reading, but it seems to be OK because function report OK.

If I test the same driver on my first MCU PIC18LF2550 it all works OK
very stable.

I have looked into the I2C bus and there are same amount of data between PIC24 and PIC18 but something gets wrong on the PIC24.

I have raised this question to my contact at CCS but thought I could ask here also. What the differences may be between PIC18 and PIC24 that could cause bit/byte error as I see it ?

Should also mention that I run on Compiler version 5.076.

//PW
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sun Jan 03, 2021 9:00 am     Reply with quote

Try specifying the clock rate. So FAST=400000.
I have seen the PIC24 drivers sometimes 'push' the clock rates higher
than chips like.
towpew



Joined: 25 Sep 2015
Posts: 24
Location: sweden

View user's profile Send private message

PostPosted: Sun Jan 03, 2021 9:17 am     Reply with quote

Ttelmah wrote:
Try specifying the clock rate. So FAST=400000.
I have seen the PIC24 drivers sometimes 'push' the clock rates higher
than chips like.


I have tried that, same result. I have tested other speeds also.
I run on 10 kHz right now because i want to use longer I2C cables later.

I have checked freq with a Saleae Logic and its 10.05 kHz. I have the same
speed on PIC18LF2550 which work.

Strange !

I can see from I2C transaction that the faulty reading is clearly missing data, many 0x00. The working I2C is numbers in all bytes.

This is the data from OK I2C com from BME280 PIC18:

EE D0 EF 60
EE F7 EF 48 BD 00 7B D4 00 60 F4

This is the I2C from faulty reading from BME280 PIC24:

EE D0 EE 60
EE F7 EF 80 00 00 80 00 00 80 00

So we can see that it has not read in the 3 sensors right.

Any clue ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sun Jan 03, 2021 12:37 pm     Reply with quote

What are your pull up resistor values?.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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