Two i2c clik doesn't work together

Fully featured PIC compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Two i2c clik doesn't work together

#1 Post by luquas » 17 Jun 2022 12:13

I'm using Necto 2.0, but in the previous version I was already having this problem. I was using clicker rtc 10 and TempHum 8, when I use one of the two, the code only works normally, but when I initialize both and try to use either only one works or the code freezes.
Attachments
20220617_065519.jpg
20220617_065519.jpg (5.05 MiB) Viewed 3354 times
20220617_065501.jpg
20220617_065501.jpg (5.71 MiB) Viewed 3354 times
20220617_065455.jpg
20220617_065455.jpg (6.07 MiB) Viewed 3354 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Two i2c clik doesn't work together

#2 Post by filip » 21 Jun 2022 11:35

Hi,

Can you please attach your project here ?

Regards,
Filip.

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#3 Post by luquas » 21 Jun 2022 22:45

#include "board.h"
#include "log.h"
#include "temphum8.h"
#include "rtc10.h"


temphum8_t temphum8;
log_t logger;
rtc10_t rtc10;
uint8_t sec_flag;

temphum8_cfg_t cfg;
rtc10_cfg_t cfg_r;

uint8_t i;
uint8_t time_hours = 0;
uint8_t time_minutes = 0;
uint8_t time_seconds = 0;

uint8_t day_of_the_week = 0;
uint8_t date_day = 0;
uint8_t date_month = 0;
uint8_t date_year = 0;

float temperaturer;


void display_day_of_the_week( uint8_t day_of_the_week )
{
if ( day_of_the_week == 1 )
{
log_printf( &logger, " Monday \r\n\n " );
}
if ( day_of_the_week == 2 )
{
log_printf( &logger, " Tuesday \r\n\n " );
}
if ( day_of_the_week == 3 )
{
log_printf( &logger, " Wednesday \r\n\n " );
}
if ( day_of_the_week == 4 )
{
log_printf( &logger, " Thursday \r\n\n " );
}
if ( day_of_the_week == 5 )
{
log_printf( &logger, " Friday \r\n\n " );
}
if ( day_of_the_week == 6 )
{
log_printf( &logger, " Saturday \r\n\n " );
}
if ( day_of_the_week == 7 )
{
log_printf( &logger, " Sunday \r\n\n " );
}
}



void application_init ( void )
{
log_cfg_t log_cfg;


/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );

// Click initialization.


rtc10_cfg_setup( &cfg_r );
RTC10_MAP_MIKROBUS( cfg_r, MIKROBUS_2 );
rtc10_init( &rtc10, &cfg_r );

Delay_ms( 1000 );

sec_flag = 0xFF;

// Set Time: 23h, 59 min and 50 sec
// rtc10_set_time( &rtc10, 19, 30, 50 );
Delay_ms( 10 );
//Set Date: 6 ( Day of the week: Saturday ), 31 ( day ), 8 ( month ) and 2019 ( year )
rtc10_set_date( &rtc10, 5, 16, 6, 2022 );
Delay_ms( 100 );

log_printf( &logger, " \r\n\n Time: %u:%u:%u ", (uint16_t)time_hours, (uint16_t)time_minutes, (uint16_t)time_seconds );

log_printf( &logger, "Date: %u. %u. 20%u. ", (uint16_t)date_day, (uint16_t)date_month, (uint16_t)date_year );
display_day_of_the_week( day_of_the_week );



temphum8_cfg_setup( &cfg );
TEMPHUM8_MAP_MIKROBUS( cfg, MIKROBUS_1 );
temphum8_init( &temphum8, &cfg );

temphum8_software_reset( &temphum8 );
temphum8_default_cfg( &temphum8 );
}


void application_task ( void )
{
float temperature;
float humidity;

// Task implementation.

temphum8_init( &temphum8, &cfg );

log_printf( &logger, "\r\n ---- Ambient data ----\r\n" );

temperature = temphum8_get_temperature_data( &temphum8, TEMPHUM8_TEMPERATURE_IN_CELSIUS );
log_printf( &logger, "** Temperature: %.2f °C \r\n", temperature );

humidity = temphum8_get_humidity_data( &temphum8 );
log_printf( &logger, "** Humidity: %.2f %%RH \r\n", humidity );

Delay_ms( 1000 );



rtc10_init( &rtc10, &cfg_r );

rtc10_get_time( &rtc10, &time_hours, &time_minutes, &time_seconds );
Delay_ms( 100 );

rtc10_get_date( &rtc10, &day_of_the_week, &date_day, &date_month, &date_year );
Delay_ms( 100 );

// if ( sec_flag != time_seconds )

log_printf( &logger, " \r\n\n Time: %d:%u:%d ", (uint16_t)time_hours, (uint16_t)time_minutes, (uint16_t)time_seconds );

log_printf( &logger, "Date: %u. %u. 20%u. ", (uint16_t)date_day, (uint16_t)date_month, (uint16_t)date_year );
display_day_of_the_week( day_of_the_week );

if ( time_seconds == 0 )
{
temperaturer = rtc10_get_temperature( &rtc10 );

log_printf( &logger, "\r\n\n Temp.:%.2f C", temperaturer);
}
log_printf( &logger, "--------------------------------------------" );

sec_flag = time_seconds;
// }


}





int main(void)
{

application_init( );


while (1)
{
application_task( );
}

return 0;
}

sgssn
Posts: 35
Joined: 13 Sep 2021 16:24

Re: Two i2c clik doesn't work together

#4 Post by sgssn » 22 Jun 2022 08:00

Hi, how did you connect the 2 boards? Do you use the same I2C-port for both or do you use two diffrent ports for the two boards?

gerhard

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#5 Post by luquas » 22 Jun 2022 11:34

Good Morning,
I use the same i2c, I'm using the PIC18F47K42.

sgssn
Posts: 35
Joined: 13 Sep 2021 16:24

Re: Two i2c clik doesn't work together

#6 Post by sgssn » 23 Jun 2022 10:01

Hi
have you tried to put the specific functions of both Click boards into your task instead of init? Perhaps it is necessary to init the I2C-port every time ne for both of your click-boards.

Gerhard

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#7 Post by luquas » 23 Jun 2022 11:10

I did that, the code crashes, executing only once each click and crashes in one of i2c's readtudo functions.

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#8 Post by luquas » 23 Jun 2022 11:51

If I initialize rtc10 first and then tempHum8 the code runs once each click and crashes, if I initialize tempHum8 first and then rtc10 the code no longer crashes normally runs rtc10 and misread tempHum.

frank.malik
Posts: 96
Joined: 09 Apr 2021 20:37

Re: Two i2c clik doesn't work together

#9 Post by frank.malik » 20 Jul 2022 18:07

Hello luquas,

just my two cents.
The PIC can run on 3.3V and 5V, however, the Temp&Hum8 is a 3.3V only click. So, is your system running completely on 3.3V ?
What board with the PIC are you using?
The I²C frequency should be maximum 400kHz ( fast mode ).
Fortunately the I²C address is completely different of the devices, this shouldn't cause a problem.

kind regards
Frank
Kind regards
Frank

Fusion for STM32 v8, STM32F407ZG@168MHz, 4" TFT capacitive
mikromedia 3, PIC32MZ2048EFH100@200MHz, 3" TFT capacitive
NECTO Studio 3.0.0, mikroC AI for ARM/PIC32, mikroSDK v.2.7.2

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#10 Post by luquas » 01 Sep 2022 22:36

I did the test with stm32, if you use click temphum8 and rtc10 together or only one or none works.
using each one individually works normally but the two together don't. I haven't tested it with other i2c clicks.
Is there any way you can try to run temphum8 and rtc10 to confirm if there is an error?

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Two i2c clik doesn't work together

#11 Post by IvanJeremic » 31 Oct 2022 12:10

Hi,

I have tested it and it worked for me, I was using Fusion for ARM v8 and STM32F407ZG.

I have attached my project below:
temp_rtc.7z
(1.56 MiB) Downloaded 62 times
Regadrs,

Ivan.

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#12 Post by luquas » 04 Dec 2022 23:49

Thanks IvanJeremic, I noticed that you used different i2c ports, when I use the same i2c ports it doesn't work.
I used different i2c ports one for temp and one for rtc and it worked too.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Two i2c clik doesn't work together

#13 Post by IvanJeremic » 08 Dec 2022 15:20

Hi,

MikroBUS1 and MikroBUS2 share I2C lines so i was using the same lines for this project.

Below i have attached another example, it is the same one except this time i used a shuttle click so i could connect both RTC10 and TempHum8 clicks to MikroBUS 1.

Regards,

Ivan.
Attachments
TEMPRTC.zip
(2.35 MiB) Downloaded 43 times

luquas
Posts: 15
Joined: 01 Jan 2020 17:29

Re: Two i2c clik doesn't work together

#14 Post by luquas » 08 Dec 2022 23:59

thanks for your attention, that way it worked.

Post Reply

Return to “PIC AI compilers”