# I2C

I2C はライブラリに収録していませんが SMBus.c というファイル名で I2C を用いるサンプルプログラムで利用されています。

{% hint style="info" %}
Samp\_I2C サンプルプログラムを参考にしてください。
{% endhint %}

```c
#include "SMBus.h"
#define EEPROM_24XX01_ADDRESS		0x50

// 初期化
void vInitHardware() {
	// SMBUS
	vSMBusInit();
}

// 24XX EEPROM 書き込み
bool_t b24xx01_Write(uint8 u8Address, uint8 *pu8Data, uint8 u8Length)
{
	uint8 n;
	bool_t bOk = TRUE;
	volatile int x;

	for(n = 0; n < u8Length; n++){
		// u8Addressと1バイトのデータ書き込み
		bOk &= bSMBusWrite(EEPROM_24XX01_ADDRESS, u8Address++, 1, pu8Data++);
		for(x = 0; x < 16000; x++);
	}
	return(bOk);
}


PUBLIC bool_t b24xx01_Read(uint8 u8Address, uint8 *pu8Dest, uint8 u8Length)
{
	bool_t bOk = TRUE;
	
	// u8Address の書き込み
	bOk &= bSMBusWrite(EEPROM_24XX01_ADDRESS, u8Address, 0, NULL);

	if(u8Length > 1){
		// u8Length分連続で読み出す。
		bOk &= bSMBusSequentialRead(EEPROM_24XX01_ADDRESS, u8Length, pu8Dest);
	}

	return(bOk);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sdk.twelite.info/hw-api-ref/perifuraru/i2c.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
