Page 1 of 1

Two i2c clik doesn't work together

Posted: 17 Jun 2022 12:13
by luquas
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.

Re: Two i2c clik doesn't work together

Posted: 21 Jun 2022 11:35
by filip
Hi,

Can you please attach your project here ?

Regards,
Filip.

Re: Two i2c clik doesn't work together

Posted: 21 Jun 2022 22:45
by luquas
#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;
}

Re: Two i2c clik doesn't work together

Posted: 22 Jun 2022 08:00
by sgssn
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

Re: Two i2c clik doesn't work together

Posted: 22 Jun 2022 11:34
by luquas
Good Morning,
I use the same i2c, I'm using the PIC18F47K42.

Re: Two i2c clik doesn't work together

Posted: 23 Jun 2022 10:01
by sgssn
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

Re: Two i2c clik doesn't work together

Posted: 23 Jun 2022 11:10
by luquas
I did that, the code crashes, executing only once each click and crashes in one of i2c's readtudo functions.

Re: Two i2c clik doesn't work together

Posted: 23 Jun 2022 11:51
by luquas
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.

Re: Two i2c clik doesn't work together

Posted: 20 Jul 2022 18:07
by frank.malik
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

Re: Two i2c clik doesn't work together

Posted: 01 Sep 2022 22:36
by luquas
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?

Re: Two i2c clik doesn't work together

Posted: 31 Oct 2022 12:10
by IvanJeremic
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 73 times
Regadrs,

Ivan.

Re: Two i2c clik doesn't work together

Posted: 04 Dec 2022 23:49
by luquas
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.

Re: Two i2c clik doesn't work together

Posted: 08 Dec 2022 15:20
by IvanJeremic
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.

Re: Two i2c clik doesn't work together

Posted: 08 Dec 2022 23:59
by luquas
thanks for your attention, that way it worked.