We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
Rating:
Author: MIKROE
Last Updated: 2019-05-29
Package Version: 1.0.0.1
mikroSDK Library: 1.0.0.0
Category: 1-Wire
Downloaded: 5813 times
Followed by: 2 users
License: MIT license
This example shows ID numbers from Unique ID Click and several Thermo Sensors (DS1820), connected on each channel. If there is no device detected on the channel, warning note is shown on TFT.
Do you want to subscribe in order to receive notifications regarding "I2C 1-Wire click" changes.
Do you want to unsubscribe in order to stop receiving notifications regarding "I2C 1-Wire click" changes.
Do you want to report abuse regarding "I2C 1-Wire click".
Front and back view of I2C 1-Wire Click Board designed in mikroBUS form factor.
View full imageLibrary Description
The library covers all the necessary functions to control I2C OneWire click board.
Library performs the communication with the device via I2C protocol by writing to registers and by reading from registers.
Key functions:
uint8_t i2conewire_setChannel( uint8_t channel )
- Set the channel function.void i2conewire_writeByteOneWire( uint8_t writeData )
- Generic One Wire writes the byte of data function.uint8_t i2conewire_readByteOneWire()
- Generic One Wire read the byte of data function.Examples description
The application is composed of the three sections :
void applicationTask() { stateOfCh = 1; i2conewire_softReset(); Delay_10ms(); i2conewire_setConfig( _I2CONEWIRE_CONFIG_1WS_HIGH | _I2CONEWIRE_CONFIG_SPU_HIGH | _I2CONEWIRE_CONFIG_APU_LOW ); Delay_10ms(); for( cntCh = 0; cntCh < 8; cntCh++ ) { i2conewire_setChannel( cntCh ); i2conewire_oneWireReset(); Delay_10ms(); i2conewire_writeByteOneWire( _I2CONEWIRE_WIRE_COMMAND_READ_ROM ); Delay_10ms(); for ( cntVal = 8; cntVal > 0; cntVal-- ) { idCode[ cntVal ] = i2conewire_readByteOneWire(); if( idCode[ cntVal ] == _I2CONEWIRE_WIRE_RESULT_OK ) { ByteToStr( cntCh, logText ); ltrim( logText ); mikrobus_logWrite( " Channel ", _LOG_TEXT ); mikrobus_logWrite( logText, _LOG_TEXT ); mikrobus_logWrite( " : No device on the channel! ", _LOG_TEXT ); Delay_100ms(); break; } else if ( stateOfCh ) { ByteToStr( cntCh, logText ); ltrim( logText ); mikrobus_logWrite( " Channel ", _LOG_TEXT ); mikrobus_logWrite( logText, _LOG_TEXT ); mikrobus_logWrite( " : ID = 0x", _LOG_TEXT ); stateOfCh = 0; } ByteToHex( idCode[ cntVal ], logText ); ltrim( logText ); mikrobus_logWrite( logText, _LOG_TEXT ); Delay_100ms(); } mikrobus_logWrite( " ", _LOG_LINE ); mikrobus_logWrite( "---------------------------------------", _LOG_LINE ); } }
Other mikroE Libraries used in the example:
I2C
UART
Conversions
Additional notes and informations
Depending on the development board you are using, you may need USB UART click, USB UART 2 click or RS232 click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.