|
| FC_IO_I2C (int bitrate=400000, int fifo_depth=16) |
|
int | WaitReady () |
|
bool | IsReady () |
|
bool | IsAddressAck () |
|
bool | StartWrite (U32 addr, const U8 *pD, int nD) |
|
bool | StartWrite (U32 addr, U8 d) |
|
bool | ContinueWrite (U32 addr, const U8 *pD, int nD) |
|
bool | StartRead (U32 addr, int nD) |
|
bool | ContinueRead (U32 addr, int nD) |
|
bool | GetReadData (U8 *pD, int nD) |
|
U8 | GetNext () |
|
U32 | GetNumValid () |
|
U32 | GetNumReady () |
|
void | ResetReadFIFO () |
|
I2C Master.
Adds to interface:
<name>_SCL : inout std_logic;
<name>_SDA : inout std_logic
where <name> is c++ object name.
Any number of instances are allowed.
#include <stdlib.h>
#include "fc_io.h"
#include "fc_system.h"
template<class T>
T& operator<<(T& os, int v)
{
char b[16];
itoa(v,b,10);
os << b;
return os;
}
int main(void)
{
temp_sens.StartWrite(0x4B,0x0B);
temp_sens.ContinueRead(0x4B,1);
temp_sens.WaitReady();
if( temp_sens.IsAddressAck())
uart_tx << "ADT7420 Id:" << int(temp_sens.GetNext()) << "\r\n";
else
uart_tx << "0x4B Addr not ok\r\n";
for(;;)
{
timer.Sleep(1000, TU_ms);
temp_sens.StartWrite(0x4B,0x00);
temp_sens.ContinueRead(0x4B,2);
temp_sens.WaitReady();
int t = (temp_sens.GetNext() << 8);
t |= temp_sens.GetNext();
t *= 10;
t >>= (3+4);
uart_tx << "Temp: " << t/10 << "." << t%10 << "\r\n";
}
}