MBED-CPLD via SPI

27 Jun 2011

Hello everyone, my application is connected to the SPI port MBED with a CPLD (MAXII epm1270), and it's all to retrieve a 24-bit word, and save it in the mbed, as two data , one composed of bits (16-24), and the other bits (4-15) thank you for your help!

27 Jun 2011

What is the question?

28 Jun 2011

Hello; my questions are: does anyone has an application like this?; what is the instruction that I can get a 24-bit word data in 3 knowing that the first is that bits [16-24], the second is bits [4-15]? know that the 24-bit word is stored in the CPLD in the cache, thank you very much for your help!

28 Jun 2011

Have you tried the SPI class?

28 Jun 2011

no, what is it?, i tried this one:

#include "mbed.h"
SPI CPLD(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    CPLD.format(16,0);
    CPLD.frequency(1000000);       
    while (1){  
    cs = 0;
     
    CPLD.write (0x8F);
    //CPLD.write (0x8F);    
   
   //CPLD.write(data2 >> 16 & 0x8f);
   //CPLD.write(data1 >> 4& 0x8f);
    int data1 = CPLD.write(0x00);
    int data2 = CPLD.write(0x02);   
    int F_ref = 3000000;
    float F_mes = (data1/data2) * F_ref; 
    pc.printf("data1 = %d\n",data1);
    pc.printf("data2 = %d\n",data2); 
    pc.printf("F_mes = %f Hz\n", F_mes);
  
    cs = 1;
   }
}

what do you think a baout this, Cheers, Zahir

28 Jun 2011

That is the SPI class that I meant. What I think is that you write 16 bits 3 times and store the 16 bit replies twice. So you sent 48 bits and received 32 bits. Are the 24 bits you are looking for anywhere in those 32 bits? Is the hardware working correctly wrt. phase, polarity and frequency? Are you sending the correct data or doesn't it matter? Your cs=1 and cs=0 are very close together, is there a minimum pulse width?

29 Jun 2011

hello, yes all my hardware works fine! and the material too, but what I miss is the instructions to put in the SPI port of MBED To retrieve the results of CPLD, do you think my porgramme is not the right, have you an example of a program to retrieve a word from a device via an SPI? thank you for your help!

29 Jun 2011

Well I guess that depends on what you have put in the CPLD, there is no way for me to find out about that.