CARME-M4 BSP  V1.5
i2c.c

Explains how to send values to the 7-digit module over I2C.

/*
* This example shows how to write to the 7-digit module over I2C.
*/
#include <stm32f4xx.h>
#include <carme.h>
#include <i2c.h>
#define SAA1064_SUBADDR_0 0x00 /* instructions byte for the SAA1064*/
#define SAA1064_ADD_12mA (1<<6) /* +12mA Digitalstrom */
#define SAA1064_ADD_9mA (11<<4) /* +9mA Digitalstrom */
#define SAA1064_ADD_6mA (1<<5) /* +6mA Digitalstrom */
#define SAA1064_ADD_3mA (1<<4) /* +3mA Digitalstrom */
#define SAA1064_SEGTEST (1<<3) /* Alle Segmente an */
#define SAA1064_ENA24 (1<<2) /* Segmente 2,4 an */
#define SAA1064_ENA13 (1<<1) /* Segmente 1,3 an */
#define SAA1064_DYNMODE (1<<0) /* Dynic Mode (multiplexed) */
/*
* hex to seven digit values
*/
uint8_t hex2sevenSeg[] = {
0x3F /* 0 */, 0x06 /* 1 */, 0x5B /* 2 */, 0x4F /* 3 */,
0x66 /* 4 */, 0x6D /* 5 */, 0x7D /* 6 */, 0x07 /* 7 */,
0x7F /* 8 */, 0x6F /* 9 */, 0x77 /* A */, 0x7C /* b */,
0x39 /* C */, 0x5E /* d */, 0x79 /* E */, 0x71 /* F */,
};
static __IO uint32_t TimingDelay;
/*
* make a delay with the frequency of the systick
*/
void Delay(__IO uint32_t nTime) {
TimingDelay = nTime;
while (TimingDelay != 0);
}
void SysTick_Handler(void) {
if (TimingDelay) {
TimingDelay--;
}
}
int main(void) {
uint16_t count = 0;
uint8_t i2c_value[5];
/* initialize systick with 1 kHz */
if (SysTick_Config(SystemCoreClock / 1000)) {
while (1);
}
/* initialize the I2C bus */
/* initialize the seven digit module */
i2c_value[0] = SAA1064_ADD_12mA | SAA1064_ENA24 | SAA1064_ENA13 | SAA1064_DYNMODE;
i2c_value[1] = 0;
i2c_value[2] = 0;
i2c_value[3] = 0;
i2c_value[4] = 0;
CARME_I2C_Write(CARME_I2C_BOARD, 0x70, SAA1064_SUBADDR_0, 0, i2c_value, sizeof(i2c_value));
for (;;) {
/* convert hex to seven digit values */
i2c_value[1] = hex2sevenSeg[(count % 0x10000) / 0x1000];
i2c_value[2] = hex2sevenSeg[(count % 0x1000) / 0x100];
i2c_value[3] = hex2sevenSeg[(count % 0x100) / 0x10];
i2c_value[4] = hex2sevenSeg[(count % 0x10) / 0x1];
/* send values to seven digit module */
CARME_I2C_Write(CARME_I2C_BOARD, 0x70, SAA1064_SUBADDR_0, 0, i2c_value, sizeof(i2c_value));
count++;
Delay(250);
}
return 0;
}