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  [ 1 post ] 
Author Message
 Post subject: friends i have a pblm in using CAN (At91SAM7X) Plz help
PostPosted: Thu Sep 10, 2009 9:50 am 
Offline

Joined: Thu Sep 10, 2009 8:38 am
Posts: 1
Hi friends,
I need to send a buffer. I place the data in the registers and give Transfer command. before placing next the next data and Transfer command i need to give some delay with out which the communication won't occur. I am using a for loop for this. I am not able to send the data continuously. any solution for this???

part of my code:

void send_packets(unsigned char*x,int size)
{
int i,z;

vParTestToggleLED(3);//LED Blink
CanTransfer canTransfer2;
canTransfer2.mailbox_number = 2;
canTransfer2.mode_reg = AT91C_CAN_MOT_TX | AT91C_CAN_PRIOR;
canTransfer2.acceptance_mask_reg = AT91C_CAN_MIDvA & (1<<(18+5));// ID 11
canTransfer2.identifier = AT91C_CAN_MIDvA & (1<<(18+5)); // ID 11
for(i=0;i<size;i++)
{
canTransfer2.data_low_reg = *x;
canTransfer2.data_high_reg = 0x00;
canTransfer2.control_reg = (AT91C_CAN_MDLC & (0x8<<16)); // Mailbox Data Length Code
CAN_InitMailboxRegistersTx( &canTransfer2 );
AT91C_BASE_CAN->CAN_TCR = AT91C_CAN_MB2;
do
{

z=Read_Status();
// printf("\n\r Status=%X",z);
}
while(z==0x40000000);


++x;
//wait();
}
}

void CAN_InitMailboxRegisters( CanTransfer *pTransfer )
{
AT91PS_CAN base_can;
AT91PS_CAN_MB CAN_Mailbox;
base_can = AT91C_BASE_CAN;
CAN_Mailbox = AT91C_BASE_CAN_MB1;
CAN_Mailbox->CAN_MB_MCR = 0x0;// MailBox Control Register
CAN_Mailbox->CAN_MB_MMR = 0x00;// MailBox Mode Register
CAN_Mailbox->CAN_MB_MAM = pTransfer->acceptance_mask_reg;// CAN Message Acceptance Mask Register
if( pTransfer->identifier != 0 ) // MailBox ID Register
{ // Disable the mailbox before writing to CAN_MIDx registers
CAN_Mailbox->CAN_MB_MAM |= AT91C_CAN_MIDE;
CAN_Mailbox->CAN_MB_MID = pTransfer->identifier;
}
else
{
CAN_Mailbox->CAN_MB_MAM &= ~AT91C_CAN_MIDE;
}
CAN_Mailbox->CAN_MB_MMR = pTransfer->mode_reg;// MailBox Mode Register
CAN_Mailbox->CAN_MB_MDL = pTransfer->data_low_reg;// MailBox Data Low Register
CAN_Mailbox->CAN_MB_MDH = pTransfer->data_high_reg;// MailBox Data High Register
CAN_Mailbox->CAN_MB_MCR = pTransfer->control_reg;// MailBox Control Register
}

typedef struct
{
volatile unsigned char mailbox_number;
volatile unsigned char test_can;
volatile unsigned int mode_reg;
volatile unsigned int acceptance_mask_reg;
volatile unsigned int identifier;
volatile unsigned int data_low_reg;
volatile unsigned int data_high_reg;
volatile unsigned int control_reg;
}CanTransfer;

int Read_Status(void)
{
int status;
status=AT91C_BASE_CAN->CAN_SR;
status=status & 0x40000000;
return status;
}


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


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: