











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












^ We use the Keil Tools for ECE189A/B^
Keil’s startup.s^ ^ Once you have specified the processor^
^ Keil startup gets CPU initialized, sets up ‘C’runtime system, then calls main() ^ Your first program can probably just startwiggling a GPIO line^
The boot process … LPC2xxx^ ^ Philips LPC2xxx family contains an integrated boot loader^
The boot process … STR71X^ ^ STR71X has configurable boot pins … booten + boot[1:0]^
(^2) IC for all processor types ^ Master mode only (i.e. processor is master)^ ^
(^2) IC --- WRITE
on a PIC
(^2) IC --- WaitI2C() on a PIC
void^ ReadBlkI2C(char addrx2,
char^ reg,
char *buffer, unsigned
char^ len)
{ StartI2C();
//^ generate a
START^ condition
WaitI2C();SSPBUF^ =^ addrx2;
//^ write
address
of^ slave
(dir=WRITE)
WaitI2C();SSPBUF^ =^ reg;^
//^ write
register within
slave^ to^ read
WaitI2C();RestartI2C();
//^ generate a
(RE)START
condition
WaitI2C();SSPBUF^ =^ addrx2|1;
//^ send (addrx2|1);
----^ address
for^ READ
WaitI2C();while(len--
^ 1)^ {
//^ for^ all but^
the^ LAST byte
to^ be^ read
SSPCON2bits.RCEN
=^ 1;^ //^ enable
receiver
WaitI2C();*buffer++
=^ SSPBUF;
//^ Read
next^ data byte
AckI2C();
//^ acknowledge
the^ read
WaitI2C();} SSPCON2bits.RCEN =
1;^
//^ enable
receiver
for last
byte
WaitI2C();*buffer++
=^ SSPBUF;
//^ read^
last^ data
byte
NotAckI2C();
//^ negative
acknowledge to show
END^ of reading
WaitI2C();StopI2C();
//^ generate
a^ STOP condition
(^2) IC --- READ on a PIC WaitI2C();}
void^ writeToReg
( unsigned
char^ reg, unsigned
char^ data
)
{ I2C_STARTGenerate (I2C0,
ENABLE);
//^ Generate
a^ START
while^ (I2C_FlagStatus
(I2C0, DIRECT, I2C_SB)
==^ RESET);
I2C_AddressSend
(I2C0, 0x86,^ I2C_Mode7,
I2C_TX);
//^ Send device address
while^ (I2C_TransmissionStatus(I2C0)
!=^ I2C_TX_ADD_OK);
I2C_FlagClear
(I2C0, I2C_ENDAD); while^ (I2C_FlagStatus
(I2C0, DIRECT, I2C_BTF)
==^ RESET);
I2C_FlagClear
(I2C0, I2C_BTF); I2C_ByteSend
(I2C0, reg);^
//^ Send target address
while^ (I2C_FlagStatus
(I2C0, DIRECT, I2C_BTF)
==^ RESET);
I2C_FlagClear
(I2C0, I2C_BTF); I2C_ByteSend
(I2C0, data);
//^ Send 1-byte payload
while^ (I2C_FlagStatus
(I2C0, DIRECT, I2C_BTF)
==^ RESET);
I2C_FlagClear
(I2C0, I2C_BTF); I2C_STOPGenerate
(I2C0, ENABLE);
//^ Generate
STOP^ condition
(^2) IC --- WRITE It would be easy to make it write an arbitrary-length block … how?^ ^ As with the PIC, the I2C subsystem must first be opened
(from ARM STM library)
unsigned^
char^ grabReg
(^ unsigned
char^ reg
)
{ unsigned
char^ I2Cdata
=^ 0; I2C_STARTGenerate
(I2C0,^ ENABLE);
//^ Generate
a^ START
while^ (I2C_FlagStatus
(I2C0,^ DIRECT,
I2C_SB)^
==^ RESET);
I2C_AddressSend
(I2C0,^ 0x86,
I2C_Mode7,
I2C_TX);
//^ Send^ device
address
while^ (I2C_TransmissionStatus(I2C0)
!=^ I2C_TX_ADD_OK);
I2C_FlagClear
(I2C0,^ I2C_ENDAD); while^ (I2C_FlagStatus
(I2C0,^ DIRECT,
I2C_BTF)
==^ RESET)
;
I2C_FlagClear
(I2C0,^ I2C_BTF); I2C_ByteSend
(I2C0,^ reg);
//^ Send^ target
address
//^ while
(I2C_FlagStatus
(I2C0,^ DIRECT,
I2C_BTF)
==^ RESET);
I2C_FlagClear
(I2C0,^ I2C_BTF); I2C_STARTGenerate
(I2C0,^ ENABLE);
//^ Generate
a^ (re-)start
//^ while
(I2C_FlagStatus
(I2C0,^ DIRECT,
I2C_SB)^
==^ RESET);
I2C_AddressSend
(I2C0,^ 0x87,
I2C_Mode7,
I2C_RX);
//^ Send^ device
address
//^ while
(I2C_TransmissionStatus(I2C0)
!=^ I2C_TX_ADD_OK);
I2C_FlagClear
(I2C0,^ I2C_ENDAD); //^ while
(I2C_FlagStatus
(I2C0,^ DIRECT,
I2C_BTF)
==^ RESET);
I2C_STOPGenerate
(I2C0,^ ENABLE);
//^ Generate
stop^ condition
//^ while
(I2C_ReceptionStatus(I2C0)
!=^ I2C_RX_DATA_OK);
I2Cdata^ =
I2C_ByteReceive(I2C0);
//^ Receive
byte
I2C_FlagClear
(I2C0,^ I2C_BTF); (^2) IC --- Read return^ I2Cdata;} Note: This code from former year’s 189 project
(from ARM STM library)
ARM Development Environment Tour^ ^ Demo Keil μVisionTools via remote desktop^