📄 test_facility.c
字号:
/**
*@file test_facility.c
*@author Zlatan Stanojevic
*/
/*
* Specify I2C_BLOCKING before including "i2c_framing_layer.h" to make the Read/Write/Get/Set
* functions wait for the message to be transferred before returning.
*/
#define I2C_BLOCKING
#include "i2c_framing_layer.h"
#include <stdio.h>
#include <services/services.h>
u8 selected_hwid = 0;
void sbCallback( u8 hwid )
{
printf( "Device detected at 0x%X\n", hwid );
if( ! selected_hwid )
selected_hwid = hwid;
}
int main()
{
u32 max_entries;
adi_int_Init( 0, 0, &max_entries, 0 ); //initialize interrupt manager used by i2c driver
/*
* The driver uses a unified init function. The first argument is the bitrate. Depending on
* whether the i2c interface is emulated or not, the init function requires three additional
* parameters: the PF numbers of the SCL and SDA pins, as well as the the number of the GP
* timer to use for internal timing.
*/
#if defined( __ADSPBF537__ )
I2CInit( 100000, 50000000 ); //100kbit
#elif defined( __ADSPBF533__ ) || defined( __ADSPBF561__ )
I2CInit( 100000, 10, 9, 1, 0 ); //100kbit; PF10 is SCL; PF9 is SDA; uses timer 1
#endif
printf( "**Bus scan**\n" );
/*
* I2CScanbus sweeps through all hardware id's. For each found device the specified callback
* function is called and the device's hardware id is passed to it.
*/
//I2CScanbus( sbCallback );
selected_hwid = 0x20;
if( selected_hwid ) //execute only if a device was found previously
{
int i;
u8 regs[][2] = {
{ 0x00, 0xff },
{ 0x01, 0xff },
{ 0x02, 0xff },
{ 0x03, 0xff },
{ 0x04, 0xff },
{ 0x05, 0xff },
{ 0x06, 0xff },
{ 0x07, 0xff },
{ 0x08, 0xff },
{ 0x09, 0xff },
{ 0x0a, 0xff },
{ 0x0b, 0xff },
{ 0x0c, 0xff },
{ 0x0d, 0xff },
{ 0x0e, 0xff },
{ 0x0f, 0xff },
};
printf( "**Register dump**\nAddr : Value\n" );
/*
* I2CGet is used to reterieve an arbitrary number of bytes starting at a specified address.
* Nevertheless some devices will not return or acknowledge more than one byte. In such
* cases a for loop as seen below has to be used.
*/
for( i = 0; i < sizeof( regs ) / 2; i++ )
{
I2CGet( selected_hwid, regs[i][0], ®s[i][1], 1 );
printf( "0x%02X : 0x%02X\n", regs[i][0], regs[i][1] );
}
}
selected_hwid = 0x2a;
if( selected_hwid ) //execute only if a device was found previously
{
int i;
u8 regs[][2] = {
{ 0x00, 0xff },
{ 0x01, 0xff },
{ 0x02, 0xff },
{ 0x03, 0xff },
{ 0x04, 0xff },
{ 0x05, 0xff },
{ 0x06, 0xff },
{ 0x07, 0xff },
{ 0x08, 0xff },
{ 0x09, 0xff },
{ 0x0a, 0xff },
{ 0x0b, 0xff },
{ 0x0c, 0xff },
{ 0x0d, 0xff },
{ 0x0e, 0xff },
{ 0x0f, 0xff },
};
printf( "**Register dump**\nAddr : Value\n" );
/*
* I2CGet is used to reterieve an arbitrary number of bytes starting at a specified address.
* Nevertheless some devices will not return or acknowledge more than one byte. In such
* cases a for loop as seen below has to be used.
*/
for( i = 0; i < sizeof( regs ) / 2; i++ )
{
I2CGet( selected_hwid, regs[i][0], ®s[i][1], 1 );
printf( "0x%02X : 0x%02X\n", regs[i][0], regs[i][1] );
}
}
while( !0 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -