/* USER MUST CUSTOMIZE THE FOLLOWING DEFINE STMTS - START */
// Enter the port used for SDA and SCL
#define SDA_PORT 0
#define SCL_PORT 0
// Enter the pin used for SDA and SCL
#define SDA_PORT_BIT 0
#define SCL_PORT_BIT 1
// Uncomment one of these define statements to select I2C bus speed
#define I2C_400_KHZ
//#define I2C_100_KHZ
// Comment out the following define statement to disable clock
// stretching in i2cRecv()
#define I2C_CLOCK_STRETCHING
/* USER MUST CUSTOMIZE THE FOLLOWING DEFINE STMTS - END */
/*
* DEMO of maxqi2c Software I²C Driver
* (uses evkits for the MAX1169 and MAXQ2000)
*
* by: Paul Holden - MAXIM INTEGRATED PRODUCTS
*
*
* DESC: Test program for the maxqi2c.c/maxqi2c.h I²C
* driver for the MAXQ2000. The program reads
* 16-bit samples from the MAX1169 (running in
* continuous conversion mode) and transmits them
* using the UART0 port.
*
* NOTE - THE FOLLOWING CODE ASSUMES THE MAXQ2000 HAS
* A Fsysclk=20MHz.
*/
#include "iomaxq200x.h"
#include "maxqi2c.h"
void main()
{
unsigned char data[2];
// 1. Init UART0
PD7_bit.bit0 = 1; // Set TX0 pin as output
SCON0 = 0x42;
SMD0 = 0x02;
PR0 = 0x07DD; // 19200bps
// 2. Init bit-banged I²C port
i2cInit();
// 3. Send initial I²C request
// [S] [ADDR+R] [A] [clock_stretch] [DATA0] [A] [DATA1] [A (termination)]
i2cData = (unsigned char *)(&data); // cast needed!
i2cDataAddr = 0x7E;
i2cDataLen = 0x0002;
i2cDataTerm = I2C_TERM_ACK;
i2cRecv();
// 4. Init continuous conversion
// [clock_stretch] [DATA0] [A] [DATA1] [A (termination)]
i2cDataAddr = 0x00;
// 5. Receive a 16-bit sample and transfer it to the UART0 port
// one byte at a time. Repeat forever...
while (1)
{
i2cRecv();
while(!SCON0_bit.TI); // Wait for UART0 Buffer to be empty
SCON0_bit.TI = 0; // Reset TI flag
SBUF0 = data[0]; // Send data byte 0
while(!SCON0_bit.TI); // Wait for UART0 Buffer to be empty
SCON0_bit.TI = 0; // reset TI flag
SBUF0 = data[1]; // Send data byte 1
}
}