I am having trouble communicating the Line Following sensor with an
HCS12 microcontroller. The controller does have the proper transceiver
module and registers associated with it. It is able to send out the
code to the sensor but does not receive proper signal back. Here is
the code with comments. Please help if you can.
#include
#include
#define TERMINAL_TIMEOUT 100
#define IBDR _P(0xE4)
int dummy=0;
int line_sensor_data=0;
void main()
{
while(1)
{
IBFD=0x27; //baud rate=16.66 kHz,
IBCR=0xB0; //enable IIC bus, interrupt disable, master-transmit mode
IBCR |= 0x30; //sets as controller as Master, sets Tx - transmit mode
IBDR = 0x50; //sends slave address out, with write bit
while((IBSR&0x02)!=0x02){}; //waiting for transfer complete
IBSR |= 0x02; //clear IBIF flag
IBCR &= 0xEF; //sets Rx, recieve mode
while((IBSR&0x01)==0x01){}; //wait for ack.
dummy=IBDR; //dummy read
IBCR |= 0x10; //sets Tx, transmit mode
IBDR = 0x01; //sends slave internal address out
while((IBSR&0x02)!=0x02){}; //waiting for transfer complete
IBSR |= 0x02; //clear IBIF flag
IBCR &= 0xEF; //sets Rx, recieve mode
while((IBSR&0x01)==0x01){}; //wait for ack.
IBCR |= 0x12; //sets Tx - transmit mode, generate repeat cycle
IBDR = 0x51; //sends slave address out, with read bit
while((IBSR&0x02)!=0x02){}; //waiting for transfer complete
IBSR |= 0x02; //clear IBIF flag
IBCR &= 0xEF; //sets Rx, recieve mode
while((IBSR&0x01)==0x01){}; //wait for ack.
line_sensor_data=IBDR; //pull data
IBSR |=0x02; //clear the IBIF interupt flag
IBCR &= 0xDF; //generates stop by switching from master to slave
}
}
------------------------------------
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )