Announcement

Collapse
No announcement yet.

uCAM- II. INITIAL command error AA0F00..0300

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • uCAM- II. INITIAL command error AA0F00..0300

    Hello everyone.

    I am new on this forum.
    Recently I purchase uCAM-II cam. Everything works fine in 4D uCam-II Demo, but when I am writing my own code I have one problems...

    I am able to:
    - Send SYNC cmd.
    - I am receiving ACK and SYNC from it after sending SYNC
    - I can also change the packet size (I didn't try to get the picture yet.),
    -Do everything using 4D uCam-II Demo

    I am not able to :
    -Set camera parameters.
    Because:
    When I am trying to send Initial Command, I receive very strange NCK respond, I haven't seen such a respond in datasheet. It looks like this: AA0F00..0300. I know what's the NCK code, because I am transmitting every data that's coming from camera to Xbee and then to my laptop. Yes I know that maybe transmitting data via Xbee is a little bit extraordinary idea, but this is one of requirement in this project.

    That's my code written in C:

    Code:
    #include <avr/io.h>
    #include <stdbool.h>
    #include <util/delay.h>
    #include <avr/interrupt.h>
    #include "Init.h"
    #include "Struct.h"
    #include "uCamII.h"
    
    #define LED1 PIN2_bm
    #define LED2 PIN3_bm
    #define LED3 PIN4_bm
    #define LED4 PIN5_bm
    #define LED5 PIN6_bm
    
    //Command for uCam-II camera
    static char sync[6]= {0xAA, 0x0D, 0x00, 0x00, 0x00, 0x00};        //Sync command needed to wake up camera
    static char syncACK[6]= {0xAA, 0x0E, 0x0D, 0x00, 0x00, 0x00};
    static char initial[6]= {0xAA, 0x01, 0x00, 0x07, 0x00, 0x07};    //Initialization Jpeg format and VGA resolution
    static char pckSize[6]={0xAA, 0x06, 0x08, 0x64, 0x02, 0x00};    //Packet size set to 100 bytes
    //Globa var.
    static struct uCamII_t uCamII_d;
    static int16_t inc;
    //Trasmit data to Xbee and then to laptop
    ISR(USARTD0_TXC_vect) {
        if(inc<6) {
            USARTD0.DATA=uCamII_d.cmd_reception[inc];
            inc++;
    
        } else inc=0;
    }
    
    //Revice data from uCAM-II
    ISR(USARTF0_RXC_vect) {
        if(uCamII_d.iUART<6){
        uCamII_d.cmd_reception[uCamII_d.iUART]=USARTF0.DATA;
        uCamII_d.iUART++;
        PORTA_OUTTGL=LED2;
        }else{
            USARTD0_TXC_vect();
            uCamII_d.iUART=0;
        }
    }
    //Trasmit data to uCAM-II
    ISR(USARTF0_TXC_vect) {
        if(uCamII_d.jUART<6) {
            USARTF0.DATA=uCamII_d.cmd_send[uCamII_d.jUART];
            uCamII_d.jUART++;
            PORTA_OUTTGL=LED4;
        }
    }
    void initialization() {
        Osc2MHz(16);
        IO_Init();
        USART_Init();
        USARTCam_Init();
        PMIC.CTRL =PMIC_MEDLVLEN_bm |PMIC_LOLVLEN_bm |PMIC_HILVLEN_bm;
        uCamII_cmdInit(&uCamII_d);
    }
    
    void uCamII_Initialize() {
        uCamII_Init(sync, &uCamII_d);
        //Try to send SYNC command as long as ACK(AA0E0DXX000000) will be received
        while(!((uCamII_d.cmd_reception[0]==0xAA) && (uCamII_d.cmd_reception[1]==0x0E || uCamII_d.cmd_reception[1]==0x0D) && (uCamII_d.cmd_reception[2]==0x0D || uCamII_d.cmd_reception[2]==0x00))) {
            uCamII_d.jUART=0;
            _delay_ms(500);
            USARTF0_TXC_vect();
            while(uCamII_d.jUART<6) _delay_us(1);
        }
        
        //Wait until camera will send SYNC
    
        while(!((uCamII_d.cmd_reception[0]==0xAA) && (uCamII_d.cmd_reception[1]==0x0D) && (uCamII_d.cmd_reception[2]==0x00))){
            PORTA_OUTTGL=LED1;
            _delay_ms(300);
        }
        //Sending SYNC ACK to camera
        uCamII_Init(syncACK, &uCamII_d);
        uCamII_d.iUART=0;
        uCamII_d.jUART=0;
        USARTF0_TXC_vect();
        _delay_ms(100);                                    //it is required to wait before 
        while(uCamII_d.jUART<6) _delay_us(1);
        PORTA_OUTSET=LED3;
        //Try to send Initial command (VGA, Jpeg) as long as ACK(AA0E01XX000000) will be received
        uCamII_Init(initial, &uCamII_d);
        _delay_ms(1000);                                    //it is required to wait before
        while(!((uCamII_d.cmd_reception[0]==0xAA) && (uCamII_d.cmd_reception[1]==0x0E) && (uCamII_d.cmd_reception[2]==0x01))) {
            uCamII_d.jUART=0;
            _delay_ms(500);
            USARTF0_TXC_vect();
            while(uCamII_d.jUART<6) _delay_us(1);
        }
    }
    int main(void) {
        sei();
        initialization();
        uCamII_Initialize();
        /* Replace with your application code */
        while (1) {
            _delay_ms(200);
            PORTA_OUTTGL=LED3;
        }
    }

    Program is stuck in a red while loop, which means that I am not receiving ACK after sending INITIAL.

    I am using custom made PCB with Xmega256A3BU.
    I am programing in C in AtmelStudio.

  • #2
    while loop is a blocking code, so , technically it's doing it's job
    Code:
    while(!((uCamII_d.cmd_reception[0]==0xAA) && (uCamII_d.cmd_reception[1]==0x0E) && (uCamII_d.cmd_reception[2]==0x01))) {
    uCamII_d.jUART=0;
    _delay_ms(500);
    USARTF0_TXC_vect();
    while(uCamII_d.jUART<6) _delay_us(1);
    } 
    why are you accessing an interrupt in a while loop? doesnt the first line of the while loop "uCamII_d.jUART=0;" block the 2nd while loop within the while loop?

    Try to change "_delay_us(1);" to a blinking led, or printing to serial monitor, if they work then thats where it's stuck
    Last edited by tonton81; 30th May 2016, 12:13 AM.

    Comment


    • #3
      the while loop is blocking, your setting jUART to 0, forcing an ISR function which has an IF statement which sets "uCamII_d.jUART++;", 1? then 1st while loop sets it 0 again, and repeats, the 2nd while loop seems to be always below 6 at that point

      Comment


      • #4
        tonton81, sorry for misunderstanding. The first while loop waits for proper ACK to come. If the different ACK then AA0e01 appear, command is send by forcing interrupt. This is method for sending data via interrupt:

        Code:
        ISR(USARTF0_TXC_vect) {
            if(uCamII_d.jUART<6) {
                USARTF0.DATA=uCamII_d.cmd_send[uCamII_d.jUART];
                uCamII_d.jUART++;
                PORTA_OUTTGL=LED4;
            }
        }
        As you can see 6 bytes of command are sent. After each byte is sent interrupt is generated and my program goes back to this method. I am sending commands like this for SYNC and packet Size and it works fine.
        I am receiving data from camera also in the interrupt.:

        Code:
        ISR(USARTF0_RXC_vect) {
            if(uCamII_d.iUART<6){
            uCamII_d.cmd_reception[uCamII_d.iUART]=USARTF0.DATA;
            uCamII_d.iUART++;
            PORTA_OUTTGL=LED2;
            }else{
                USARTD0_TXC_vect();
                uCamII_d.iUART=0;
            }
        }
        After I received whole command I am sending this command to Xbee and then to my "Ground station", by generating this interrupt: USARTD0_TXC_vect(); (another USART)

        So I don't know why my method is not working with

        Comment

        Working...
        X