Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
i2c_mbed_fpga.cpp
- Committer:
- wuliqunyy
- Date:
- 2020-12-04
- Revision:
- 0:fe3c7dde9771
- Child:
- 5:daab0e0e67e2
File content as of revision 0:fe3c7dde9771:
#include "mbed.h"
#include "i2c_mbed_fpga.h"
char i2cKey[4] = {0x13, 0xA4, 0xD0, 0xD0};
char CtrPortWactive[4] = {0x00, 0x30, 0x00, 0x71};
char CtrPortRactive[4] = {0x00, 0x30, 0x00, 0x01};
/** i2c write to slave DUT
*
* @param i2c_master specifies the i2c interface
* @param word is considered as 4byte char data
*/
int i2c_word_write(I2C i2c_master, char *word){
int ack=1;
if(ack!=0)
{
ack = i2c_master.write(i2c_slave_addr, word, 4, 0);
wait_ms(1);
}
if(ack==0)
return 0;
else
return 1;
}
/** i2c read from slave DUT
*
* @param i2c_master specifies the i2c interface
* @param word is 4byte, first 2bytes as addr, the rest 2bytes to store data
*/
int i2c_word_read(I2C i2c_master, char *word){
int ack=1;
if(ack!=0)
{
ack = i2c_master.write(i2c_slave_addr, word, 2, 1);
ack += i2c_master.read(i2c_slave_addr, word+2, 2, 0);
wait_ms(1);
}
if(ack==0)
return 0;
else
return 1;
}
/** i2c enter key
*
* @param specifc key needed to enter i2c mode of DUT
*/
int i2c_keyEntry(I2C i2c_master){
return i2c_word_write(i2c_master, i2cKey);
}
/** Activate eeprom for write operations
*
* @param specifc key needed to enter i2c mode of DUT
*/
int ctrPort_WriteActive(I2C i2c_master){
return i2c_word_write(i2c_master, CtrPortWactive);
}
/** Activate eeprom for read operations
*
* @param specifc key needed to enter i2c mode of DUT
*/
int ctrPort_ReadActive(I2C i2c_master){
return i2c_word_write(i2c_master, CtrPortRactive);
}