You are here: Forum Home → ANT Developers Forums → ANT General Questions → Thread
#define SYNC_BYTE 0xA4
uint8 system_reset_msg[3]={0x01, 0x4A, 0x00};
uint8 channel_status_msg[4]={0x02, 0x52, 0x00, 0x00};
uint8 channel_open_msg[3]={0x01, 0x4B, 0x00};
uint8 channel_unassign_msg[3]={0x01, 0x41, 0x00};
uint8 channel_brdcst_data_msg_master[11]={0x09, 0x4E, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD};
uint8 channel_assign_msg_master[5]={0x03, 0x42, 0x00, 0x10, 0x00};
uint8 channel_id_msg_master[7]={0x05, 0x51, 0x00, 0x31, 0x00, 0x01, 0x03};
uint8 channel_period_msg_master[5]={0x03, 0x43, 0x00, 0x00, 0x10};
uint8 channel_freq_msg_master[4]={0x02, 0x45, 0x00, 0x00};
uint8 channel_assign_msg_slave[5]={0x03, 0x42, 0x00, 0x00, 0x00};
uint8 channel_id_msg_slave[7]={0x05, 0x51, 0x00, 0x31, 0x00, 0x01, 0x03};
uint8 channel_period_msg_slave[5]={0x03, 0x43, 0x00, 0x00, 0x10};
uint8 channel_freq_msg_slave[4]={0x02, 0x45, 0x00, 0x00};
uint8 ant_init(void)
{
GPIO_Enable(136);
GPIO_SetDirection(136, SCI_FALSE);//set RTS as input
SCI_Sleep(100);
ant_ComInit(COM_0);
SCI_Sleep(100);
return 0;
}
//check the RTS signal to see whether the ANT is ready to receive message
BOOLEAN ant_is_busy(void)
{
BOOLEAN gpio_value;
gpio_value = GPIO_GetValue(136);
if(gpio_value == SCI_TRUE)
return SCI_TRUE;
else
return SCI_FALSE;
}
uint8 ant_send_msg(uint8 *msg, uint8 cnt)
{
uint8 i=0, com_buf[128], wr_buf[128], checksum = 0;
SCI_MEMSET(wr_buf, 0, 128);
checksum = SYNC_BYTE;
wr_buf[0] = SYNC_BYTE;
for(i=1; i <= cnt; i++)
{
wr_buf[i] = msg[i-1];
checksum = checksum ^ wr_buf[i];
}
wr_buf[i] = checksum;
while(ant_is_busy() == SCI_TRUE) {;}
ant_ComWrite(wr_buf, cnt+2);
SCI_Sleep(100);
SCI_MEMSET(com_buf, 0, 128);
ant_ComRead(com_buf, sizeof(com_buf));
SCI_Sleep(100);
return 0;
}
uint8 ant_channel_setup_master(void)
{
ant_send_msg(system_reset_msg, 3);
ant_send_msg(channel_assign_msg_master, 5);
ant_send_msg(channel_id_msg_master, 7);
ant_send_msg(channel_period_msg_master, 5);
ant_send_msg(channel_freq_msg_master, 4);
ant_send_msg(channel_open_msg, 3);
ant_send_msg(channel_brdcst_data_msg_master, 11);
return 0;
}
uint8 ant_channel_setup_slave(void)
{
uint8 i=0, com_buf[128];
ant_send_msg(system_reset_msg, 3);
ant_send_msg(channel_assign_msg_slave, 5);
ant_send_msg(channel_id_msg_slave, 7);
ant_send_msg(channel_period_msg_slave, 5);
ant_send_msg(channel_freq_msg_slave, 4);
ant_send_msg(channel_open_msg, 3);
while(1)
{
SCI_MEMSET(com_buf, 0, 128);
ant_ComRead(com_buf, sizeof(com_buf));//here i didn't get any data
SCI_Sleep(100);
}
return 0;
}