Interperting hex commands for a camera on a data sheet - camera

I'm reading this data sheet for a camera.
Datasheet
I have my Arduino communicating with the camera over SPI and can send it a command to take a picture.
The last step is to send a command to retrieve the data, which I'm stuck on.
On page 4 the command DATA is
FF FF FF 0x0A 0X05 Length Byte 0 Length Byte 1 Length Byte 2'
So in code the command would look like this. But how do I figure out what Length Byte 0, Byte 1 Length Byte 2 are??
uint8_t DataCmd[8] = { 0xff, 0xff, 0xff, 0x0a, 0x05, ?, ?, ?};
On page 6 it says
Image Length = len 0 + Len 1 * 100h + Len 2 * 10000h
What does this mean? And how to I translate it into the three parameters that I need for my command?

As you can read, the DATA command is a command sent BY the camera to you. The flow chart at page 9 shows what it does
When the camera receives "get picture",
is the picture ready? if not send a NAK and return
if it is send an ACK
send the DATA command (with the length)
send the picture data
wait for the host to send an ACK
Page 10 has the steps you have to perform. I'll copy them here for future reference:
Establish communication with the camera
Send command INIT (e.g. FFFFFF0100870107h)
Wait for the ACK (e.g. FFFFFF0E01nn0000h)
Send command SELECT IMAGE QUALITY (e.g. FFFFFF1000000000h)
Wait for the ACK (e.g. FFFFFF0E10nn0000h)
Send command GET PICTURE (e.g. FFFFFF0405000000h)
Wait for the ACK (e.g. FFFFFF0E04nn0000h)
Wait for the DATA (e.g. FFFFFF0AnnL0L1L2h)
Receive Image Data
The DATA packet contains L0, L1 and L2, which contain the data image length. L0 is the low-order byte, so if L0 = 0x45, L1 = 0x23, L2 = 0x01 the total length will be 0x012345 = L0 + L1 * 0x100 + L2 * 0x1000; this means that the image is 0x12345 = 74565 bytes, so you know how many bytes you will receive before actually receiving them

Related

How to get SPI running between EtherCat EVB-LAN9252-SPI board and STM32 Microcontroller?

I'm trying to create a simple EtherCat slave. The hardware I use is the EVB-LAN9252 and a NUCLEO-G491RE board. As Slave Stack I use SOES. The EtherCat SDK (slave editor) from rt-labs is used to generate the ESI file, a bin file for the EEPROM and some c files. With the slave explorer from the EtherCat SDK the slave can then be tested.
very much the same as in this project
After I built the project and started the Master (EtherCat Explorer), the slave could enter op-mode. But I couldn't read the Object Dictionary. I checked SPI and it isn't doing what I'm expecting it to do.
To check if SPI is working properly I tried to read out the BYTE_TEST register (0x64), which returns the value 0x431400 instead of 0x87654321. To read the register I used the following code (modified function from SOES to run on Cube IDE):
uint32_t lan9252_read_32 (uint32_t address)
{
uint8_t data[7];
uint8_t result[7];
memset(data, 0, sizeof(data));
data[0] = ESC_CMD_READ; //0x03
data[1] = ((address >> 8) & 0xFF);
data[2] = (address & 0xFF);
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, RESET);
HAL_SPI_TransmitReceive(&hspi1, data, result, sizeof(data), HAL_MAX_DELAY);
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, SET);
return((result[6] << 24) |
(result[5] << 16) |
(result[4] << 8) |
result[3]);
}
oscilloscope image
My SPI settings (STM32 operates as ful duplex master):
Data Size: 8 Bits
First Bit: MSB First
Baud Rate: 1.328125 MBits/s
Clock Polarity: HIGH
Clock Phase: 2 Edge (I tried all combinations of Clock Polarity and Clock Phase so i don't think the problem is there)
The EtherCAT Slave Controller Configuration Area of the EEPROM has the value 80 0F 00 CC 88 13 FF 00 00 00 00 80 00 00 57 00. The first Byte is the initialization value for the PDI Control register (0x140 -0x141). 0x80 sets the the Process Data Interface to SPI, so the problem can't be there either.

How to erase msp430f2619 flash using bsl?

I want to do mass erase on my msp430f2619 using bsl. I use software jump in my code to invoke bsl. I send 0x80, get 0x90 from BSL(ack). Then i send mass erase command and get 0x90 again. Then i power off my device, then i power on the device, then i send 0x80 and get 0x90, that means there was no mass erase operation.
Read command is not working too. I send password (0xFF 32 times), after that send rx command, then i get few coorect bytes, and then infinite raw of 0xff.
I think i miised something before jump to bsl, please give an example code, or step by step instruction on how to make software jump to bsl and make it work correctly.
If you are sending 0x80 only, then get back 0x90, this confirms you have entered into the BSL since this completes the required synchronization sequence (see section 2.1 of this document). You should not require the "RX password" command since the "Mass erase" command is not protected.
The next sequence after the synchronization is to send the desired command, which should be the "Mass erase". There is a format to each of the BSL commands called the data frame. You want to send the following data frame: eight mandatory bytes (note two dummy bytes), and two checksum bytes. Note the "Mass erase" command does not contain data bytes, but you need to calculate the checksum bytes. Here are the bytes to be sent to perform the mass erase:
80 18 04 04 dd dd 06 A5 CL CH
Where: dd = dummy bytes (any value accepted), CL = Checksum low, CH = Checksum high
After sending this data frame then you should receive the ACK (0x90) byte. Then power off the device.

Declaring 16bit memory variable in assembly

I'm starting to study assembly for PIC18f4550 and I've been trying to do some activities and I don't know how to solve it. According to the activity, Using MPLABX, I'm supposed to sum 2 16bit variables and store the result on a third 16 bit variable.
I was able to sum and store the result on the third variable but I have no idea how to declare these variables in 16bit.
; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR
INCLUDE
RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program
; TODO ADD INTERRUPTS HERE IF USED
MAIN_PROG CODE ; let linker place main program
START
clrw ;clear the w register
num1 equ 00000 ;declares 3 variables and their initial values
num2 equ 00001
result equ 00002
movlw H'4F'
movwf num1
movlw H'8A'
movwf num2
movf num1,W ;moves num1 value to w register
addwf num2,W ;sums num2 and w and stores it in w itself
movwf resultado ;moves w to the result register
END
I need to check if my code is actually correct (Im totally new on assembly) and how to declare these 3 variables in 16bit format. Thanks in advance!
The PIC18 is a 8 bit controller. If you want to add two 16 bit variables you had to do it byte by byte.
Maybe you don't want to work with an absolue address and work with the linker:
udata_acs H'000'
num1_LSB RES 1 ;reserve one byte on the access bank
num1_MSB RES 1 ;
You also could reserve two bytes for a name:
udata_acs H'000'
num1 RES 2 ;reserve two bytes on the access bank
Know you could access the second byte with :
movwf num1+1
And always remember to check the carry bit to get the MSB of an addition.

Unpack binary data read from serial port in LabVIEW

I am reading data from 3, 12bit ADCs and streaming the data constantly to computer by USB (UART) . Each package of the data stream is as follows:
It has 6 bytes of data from 3 ADCS which the 8 bits LSB of each ADC is in one byte and the rest 4 bits MSB is in another byte. Also there are 2 bytes with "z" and "y" character at the end of the package of data to realize the start and end of each package. How do I unpack this data with LabVIEW?
Here is the answer for unpacking the data:

C++ CLI string processing from serial port

windows 7, msvs2010, C++ CLI
I want to save last 50 chars into a file from data received from serial port. Normally, to receive all data I would do this:
//Reading all exsisting data in serialport buffer
String^ data = _serialPort->ReadExisting();
sw->Write(data);
delete (IDisposable^)sw;
What should I do if I want to save only last, say, 50 char?