i am working with arduino ATmega 2560. i interfaced it with a CAN controller through UART port. What i have to do is to capture image from 2 cameras and break these data into packets and making frames and then send them to CAN controller.The entire size of frame is of 8 byte. The frame contains the following fields:
1.flag (8 bit) at both ends of frame which tells the starting and ending of frame.
2.address of cameras (2bits).
3.start bit before payload field (1 bit).
5.stop bit after payload field (1 bit).
6.sequence no, it depends on the no. of frames.
the problem i am facing how can i code this frame into arduino so that i can easily transmit frame and another thing i have to extract payload field from frame but i have no idea how to do this!! please help.
How big is the sequence number field? That defines exactly where the payload field is in the 64 bits of data, and how big it is.
The start and end 8 bits are easy.
uint8_t sFlag = someValue;
Setting the address of the camera is easy - two calls to bitWrite();
The start bit and end bit are just as easy.
I'd be surprised if the payload field turned out to be something other than a multiple of 8 bits in length. If that is the case, read that multiple of bytes from the camera, and use bit-shifting to copy the data from the camera into the payload portion of the array.
Extracting the data is similar, except that the shift happens in the other direction.
one thing i forgot to mention is CRC field that comes after stop bit of payload to chk if there is any error or not. the CRC field is for 8bit data.