Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Confused about CAN bus source code?
PostPosted: Wed Jul 23, 2008 8:05 am 
Offline

Joined: Wed Jul 23, 2008 7:24 am
Posts: 1
Hi, i'm confused about the CAN bus source code below,

//------------------------------------------------------------------------------
/// Test CAN0 Mailbox 0 transmitting to CAN1 Mailbox 0
//------------------------------------------------------------------------------
void Test1(void )
{
#if defined AT91C_BASE_CAN1_MB0
CAN_ResetAllMailbox();

trace_LOG( trace_INFO, "With Interrupt ");
trace_LOG( trace_INFO, "CAN0 Mailbox 0 transmitting to CAN1 Mailbox 0\n\r");
// Init CAN1 Mailbox 0, receive,
CAN_ResetTransfer( &canTransfer2 );
canTransfer2.can_number = 1;
canTransfer2.mailbox_number = 0;
canTransfer2.mode_reg = AT91C_CAN_MOT_RX;
canTransfer2.acceptance_mask_reg = AT91C_CAN_MIDvA | AT91C_CAN_MIDvB;
canTransfer2.identifier = AT91C_CAN_MIDvA & (0x07<<18);
canTransfer2.data_low_reg = 0x00000000;
canTransfer2.data_high_reg = 0x00000000;
canTransfer2.control_reg = 0x00000000;
CAN_InitMailboxRegisters( &canTransfer2 );

// Init CAN0 Mailbox 0, transmit
CAN_ResetTransfer( &canTransfer1 );
canTransfer1.can_number = 0;
canTransfer1.mailbox_number = 0;
canTransfer1.mode_reg = AT91C_CAN_MOT_TX | AT91C_CAN_PRIOR;
canTransfer1.acceptance_mask_reg = 0x00000000;
canTransfer1.identifier = AT91C_CAN_MIDvA & (0x07<<18);
canTransfer1.data_low_reg = 0x11223344;
canTransfer1.data_high_reg = 0x01234567;
canTransfer1.control_reg = (AT91C_CAN_MDLC & (0x8<<16));
CAN_InitMailboxRegisters( &canTransfer1 );

while( CAN_STATUS_SUCCESS != CAN_Read( &canTransfer2 ) ){}
while( CAN_STATUS_SUCCESS != CAN_Write( &canTransfer1 ) ){}


// wait answer
while( CAN_IsInIdle(&canTransfer2) ) {}
while( CAN_IsInIdle(&canTransfer1) ) {}

trace_LOG( trace_DEBUG, "Read data low 0x%X\n\r", canTransfer2.data_low_reg);
trace_LOG( trace_DEBUG, "Read data high 0x%X\n\r", canTransfer2.data_high_reg);
if( (canTransfer2.data_low_reg == 0x11223344)
&&(canTransfer2.data_high_reg == 0x01234567)
&&(canTransfer2.size == 8)) {
trace_LOG( trace_INFO, "Test passed\n\r");
}
else {
trace_LOG( trace_INFO, "Test ERROR\n\r");
}
#endif
}

***********************************************
why does the CAN_Read() is executed before the CAN_Write()?

Thanks.

andershen


Top
 Profile  
 
 Post subject: CAN source code
PostPosted: Sat Aug 30, 2008 2:24 pm 
Offline

Joined: Sat Aug 30, 2008 2:16 pm
Posts: 1
Location: Italy
The same question I would like an answer to! Any way, it is not the only strange thing about the CAN programming: in the computation of the baudrate settings there is a strange 16 factor in the source code that is not present in the CAN section of the datasheet!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2008 9:35 pm 
Offline

Joined: Sun Aug 31, 2008 9:14 pm
Posts: 2
hello

I don't know who wrote the CAN module but he has a very strange method.

As far as i understood, the read is before the write becasue the read function doesn't actually read the data, but it allows data reading.
Just look at the code of the READ/WRITE funcs.

I wrote my own CAN module and i didn't used this code package.


regards
t.e.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: