This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[BBB-PRU] Acquire SPI with PRU input/output

Hi !


I'm trying to acquire data from SPI ( clk=1.5 Mhz) only using two inputs of one of the PRU's BBB.

I've just written a little piece of code to detect when the clock is high , to know when can

i read my data input. Then i wait until the clock goes down etc ...

It works pretty well but i've noticed that sometimes it seems as if some bits are not acquired properly,so..

sometimes my programm gives me exactly what i've sent on the board, sometimes not.. it's really annoying because i don't see where could i've

made something wrong ..

If you have any ideas  to solve my problem, or another way to do that, please let me know !

Thanks

  • Hi,

    We can't help in anyway without seeing the code you have written.
  • Hi Biser,

    Here it is,



    #define NB_INT_STOCKES 7 #define INTERRUPT 0x20 #define VECT_OUTPUT 0x11 #define SHARED_RAM 0x10000 #define PRU0_RAM 0x0 #define PRU0_CONTROL_REGISTER 0x22000 #define PRU0_STATUS_REGISTER 0x0004 #define PRU0_WAKEUP_ENABLE_REGISTER 0x0008 #define PRU0_CYCLE_COUNT_REGISTER 0x000C // Bits PRU Control Register #include <time.h> #define PRU0_CONTROL_REGISTER_SOFT_RESET 0 #define PRU0_CONTROL_REGISTER_ENABLE 1 #define PRU0_CONTROL_REGISTER_SLEEPING 2 #define MASK_PRU0_CONTROL_REGISTER_COUNTENABLE 0x8 volatile register unsigned int __R30; volatile register unsigned int __R31; int main(){ unsigned int *addShared, *addData; unsigned int * pointeur; unsigned int * pointeurControlerRegister; //pointeur pour modifier/lire le registre de configuration unsigned int * pointeurShared; //pointeur pour acceder a la memoire partagee unsigned int * pointeurRAM; //pointeur pour acceder a la memoire partagee //unsigned int i; //compteur pour boucle pointeurShared=(unsigned int *)SHARED_RAM; pointeurRAM=(unsigned int *)PRU0_RAM; pointeurControlerRegister=(unsigned int *)(PRU0_CONTROL_REGISTER); // le pointeur pointe vers le debut du registre de controle *(pointeurControlerRegister)=*(pointeurControlerRegister)|MASK_PRU0_CONTROL_REGISTER_COUNTENABLE; //on autorise le comptage pointeurControlerRegister=(unsigned int *)(PRU0_CONTROL_REGISTER+PRU0_CYCLE_COUNT_REGISTER); //on pointe ensuite vers le registre de comptage de cycle int taille, masque; addShared = (unsigned int *)0x00010000; taille = 0x40000000; masque = 0x2200; int nb_bits=8; int compteur=0; int nb_enregistrement=0; compteur=0; int i=0; int compteur_boucle=0; //while(compteur<200) for(i=0;i<2500;i++){ *(addShared++)=0x10000000; } addShared = (unsigned int *)0x00010000; *addShared=9; while(compteur_boucle<3){ addShared = (unsigned int *)0x00010000; while(nb_enregistrement<2500){ register int reg=0; for(i=0;i<nb_bits;i++){ while(((__R31>>15)&0x1)==0){} // until the clock goes up reg=(reg<<1)|((__R31>>14)&0x1);//} // i read my data input while(((__R31>>15)&0x1)==1){} // until the clock goes down } *(addShared++)=reg; //record it on the shared memory nb_enregistrement++; //int test=0; } compteur_boucle++; } __R31=35; __halt(); } }

    Best regards,

  • Hi,

    I finally found what was wrong : i just needed to connect the dgnd pin to the ground, and then it worked !

    My C program for handling SPI was right , maybe  could it help some of you !

    Regards,

  • Thanks for updating the thread!