Thank you sir for you help. I did what you said and it's somehow working but I have a small problem.
I did the following configurations as you suggested
//Init ADC CTRL register MOV r2, 0x44E0D040 MOV r3, 0x00000007 //5 SBBO r3, r2, 0, 4 //set clk div to 0 mov r2,0x44e0d04c mov r3, 0x00000000 SBBO r3, r2, 0, 4 //Enable ADC STEPCONFIG 1-7 MOV r2, 0x44E0D054 MOV r3, 0x000000fe SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 1 MOV r2, 0x44E0D064 MOV r3, 0x00000000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 2 MOV r2, 0x44E0D06c MOV r3, 0x00080000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 3 MOV r2, 0x44E0D074 MOV r3, 0x00100000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 4 MOV r2, 0x44E0D07c MOV r3, 0x00180000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 5 MOV r2, 0x44E0D084 MOV r3, 0x00200000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 6 MOV r2, 0x44E0D08c MOV r3, 0x00280000 //one-shot mode SBBO r3, r2, 0, 4 //Init ADC STEPCONFIG 7 MOV r2, 0x44E0D094 MOV r3, 0x00300000 //one-shot mode SBBO r3, r2, 0, 4
If I'm not wrong, these configurations can be used to read from all 7 analog inputs using the following:
.macro READADC //Initialize buffer status (0: empty, 1: first buffer is ready, 2: second buffer is ready) MOV r2, 0 SBCO r2, CONST_PRUSHAREDRAM, 0, 4 INITV: MOV r5, 0 //Shared RAM address of ADC Saving position MOV r6, BUFF_SIZE //Counting variable READ: //Read ADC from FIFO0DATA MOV r2, 0x44E0D100 //////////////////////////////////////////// mov r1, 0x7 mov r7, 0 rree:LBBO r3, r2, r7, 4 //Add address counting ADD r5, r5, 4 //Write ADC to PRU Shared RAM SBCO r3, CONST_PRUSHAREDRAM, r5, 4 sub r1,r1,1 add r7,r7,4 qbne rree,r1,0 //////////////////////////////////////////// DELAY SUB r6, r6, 0x1c //4 MOV r2, HALF_SIZE QBEQ CHBUFFSTATUS1, r6, r2 //If first buffer is ready QBEQ CHBUFFSTATUS2, r6, 0 //If second buffer is ready QBA READ //Change buffer status to 1 CHBUFFSTATUS1: MOV r2, 1 SBCO r2, CONST_PRUSHAREDRAM, 0, 4 QBA READ //Change buffer status to 2 CHBUFFSTATUS2: MOV r2, 2 SBCO r2, CONST_PRUSHAREDRAM, 0, 4 QBA INITV //Init ADC CTRL register MOV r2, 0x44E0D040 MOV r3, 0x00000006 SBBO r3, r2, 0, 4 //Disable ADC STEPCONFIG 1-7 //MOV r2, 0x44E0D054 //MOV r3, 0x00000000 //SBBO r3, r2, 0, 4 //Send event to host program MOV r31.b0, PRU0_ARM_INTERRUPT+16 HALT .endm
Now my problem is somehow silly but it will affect my results. When reading the values from the host code, I can use the line code: (sharedMem_int[OFFSET_SHAREDRAM + 1 + i] & 0x000f0000) >> 16 to know from which analog pin the value came from (using the ID tag). The problem is that the pins are not fairly multiplexed (I mean that the TDM is not fair with all the pins). I might get values from pin0, pin1, pin1, pin1, pin2, ... (Notice that there are some consecutive values that came from the same pin). How can I force the program to read the values in a fair way (0,1,2,3,4,5,6,0,1,...)?
Another question is how to force the program to start reading always from AIN0? and how to let the PRU release the devices or the resource after halting (or immediately before halting)? When I execute the code and then try running the following command in the terminal: cat /sys/devices/ocp.3/helper.15/AIN0 I get an error : Resource or Device busy although I used the instructions:
//Disable ADC STEPCONFIG 1-7 MOV r2, 0x44E0D054 MOV r3, 0x00000000 SBBO r3, r2, 0, 4
Thank you again for you help.