Cannot measure SPI2 clock pin. - QE128

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cannot measure SPI2 clock pin. - QE128

4,701 Views
FWFan
Contributor III
Hi All,
 
I'm trying to use my QE128 (8-bit) SPI2 functions, but I cannot seem to measure the SPI clock using my scope.  I am not seeing any clock signal from the pin.  Am I not setting something correctly?  No clock means no transfering of data right?
I'm including my file just in case. 
 
Thank you,
FWFan
 
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-10-23 03:27 PM
Labels (1)
0 Kudos
Reply
15 Replies

2,777 Views
Ake
Contributor III
Hi,
I looked at your code and saw the following:
//************************************************************************
// This routine is used for writing to the Toshiba TB62709 Display driver. 
//************************************************************************
void display_out(unsigned char command, unsigned char data)
  {  
    PTDD_PTDD3 = 0;     // disable chip select
  
    if(SPI1S_SPTEF)     // if it is empty, load up the data
    {
      SPI2D = command;  // output address (command)
    }
  
    if(SPI1S_SPTEF){
      SPI2D = data;     // output data   
      }
    
  
    PTDD_PTDD3 = 0;      // enable chip select (high active)
   }
My first reaction was:
    PTDD_PTDD3 = 0;     // disable chip select 
    PTDD_PTDD3 = 0;      // enable chip select (high active)
 
shouldn't one of these be
    PTDD_PTDD3 = 1;      // enable chip select (high active)
???
 
Then I looked at the code:
    if(SPI1S_SPTEF)     // if it is empty, load up the data
    {
      SPI2D = command;  // output address (command)
    }
  
    if(SPI1S_SPTEF){
      SPI2D = data;     // output data   
      }
shouldn't the SPI1 be replaced by SPI2??
 
Now I have not run the code, so this is just idle thoughts of an idle mind.
So my "improvements" may be catastrophic.
 
Regards,
Ake

0 Kudos
Reply

2,777 Views
bigmac
Specialist III
Hello FWFan,
 
In addition to the inconsistencies observed by Ake, I would suspect that you would need to enable the chip select during the SPI transfer, and disable the chip select when the transfer is complete.  You seem to indicate the opposite conditions.  Also the chip select should not be disabled until the transfer of the two bytes is complete.
 
Your code does not clear the SPIF flag on the completion of each transfer.  The SPIF flag must be cleared immediately after each byte transfer has completed, otherwise an overrun condition will occur.
 
Also, the use of the if  statements would seem to be inapropriate for what you are trying to achieve.  Perhaps your code should appear similar to the following:
 
void display_out( unsigned char command, unsigned char data)
{  
    PTDD_PTDD3 = 1;        // Enable chip select
    while (!SPI2S_SPTEF);  // Wait until SPI is ready
    SPI2D = command;       // Send command byte
    while (!SPI2S_SPIF);   // Wait until transfer is complete
    (void)SPI2D;           // Clear flag
    SPI2D = data;          // Send data byte
    while (!SPI2S_SPIF);   // Wait until transfer is complete
    (void)SPI2D;           // Clear flag
    PTDD_PTDD3 = 0;        // Disable chip select
}
  
Regards,
Mac
 
0 Kudos
Reply

2,777 Views
Lundin
Senior Contributor IV
Slave/chip select is active low on all SPI interfaces and on most peripherals / ICs.
0 Kudos
Reply

2,777 Views
bigmac
Specialist III
Hello,
 
I just checked out the datasheet for the Toshiba device, to find that there is no "chip select" pin.  In fact there is a "load" pin that when strobed, will transfer the contents of the shift register to a holding register.  This requires a positive going pulse at the completion of the transfer of each 16 bits, assuming only a single device is present
 
So the previous code that I posted might be modified to the following, to take this into account.
 
void display_out( unsigned char command, unsigned char data)
{  
    PTDD_PTDD3 = 0;        // Ensure load pin inactive
    while (!SPI2S_SPTEF);  // Wait until SPI is ready
    SPI2D = command;       // Send command byte
    while (!SPI2S_SPRF);   // Wait until transfer is complete
    (void)SPI2D;           // Clear flag
    SPI2D = data;          // Send data byte
    while (!SPI2S_SPRF);   // Wait until transfer is complete
    (void)SPI2D;           // Clear flag
    PTDD_PTDD3 = 1;        // Generate strobe pulse at load pin
    PTDD_PTDD3 = 0;
}
 
Regards,
Mac
 
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Hi Mac,
 
I got the SPI to work with my 7-segment display over the weekend.
Thank you very much for your help.
 
I have a question to ask you though.  I tried to use a float type in my
program and I am having problem linking the program. 
Is this a common problem?
 
Thank you,
FWFan
0 Kudos
Reply

2,777 Views
bigmac
Specialist III
Hello FWFan,


FWFan wrote:
...  I tried to use a float type in my program and I am having problem linking the program. 
Is this a common problem?

This is because you are not linking the library files that support floating point.
 
The simplest way of correcting the problem would be to create a new project using the project wizard.  Floating point support is one of the choices that is made during project creation.  Your existing source files can be copied to the new project.
 
Regards,
Mac
 
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Hi Mac,
 
How about using snprintf()?
I tried this too but the compiler won't seem
to accept the function. 
 
Basically, I'm trying to write my float result
to a string.  Then parse this string to get
the number to display on the 7-segment display.
 
Thank you,
FWFan
0 Kudos
Reply

2,777 Views
bigmac
Specialist III
Hello FWFan,
 
I assume that you mean "sprintf".  Did you #include the header file "stdio.h" prior to calling the sprintf() function?  This file contains the function prototype.
 
Regards,
Mac
 
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Hi Bigmac,
 
Thank you very much for your help and others. 
I've finally finished what I've set out to do.
I've learned ADC, SCI and SPI.
I've included my file so other beginners can
see some example codes.  And perhaps
you guys can spot something that I can
improve on, like the way I've tried to display
the 7-segment display. 
 
In any case, thank you for all your help.
Next stop, I2C.  Hope to get your help.
 
FWFan
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Hi Mac,
 
Yes, I did, but it still doesn't understand what I was doing.
I tried both sprintf() and snprintf().  The reason I used snprintf() is
to limit the buffer length.  I heard this was a better function to use
than just sprintf().
 
Also, does the #include increase the program size too much?
 
Thank you for your help.
FWFan
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Thank you very much Mac.
I will give it a try.
 
FWFan.
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Thank you Lundin.  I think it is active low also for the Toshiba driver.  The thing is that it is confusing on what they want me to do.  I thought sometimes they want the address to be sent with a high pulse and the data at a low pulse.  But at other part of the datasheet, it seems they want everything at low pulse.  I'm trying to understand the datasheet.  Thank you for your help.
 
Hi Mac.  I really appreciate your help.  It's like you're doing all the work for me.  I tried your codes last night and I was able to get the LEDs to turn on finally.  But it didn't do what I expected.  But I think that is on my end.  I did not know that I'm suppose to look for the read empty flag also (SPRF).  I thought I'm suppose to be worrying about the transfer empty flag only (SPTEF).  In any case, I will try your newer codes tonight.
 
Thank you very much,
FWFan
0 Kudos
Reply

2,777 Views
bigmac
Specialist III
Hello,
 
My previous reference to the SPIF flag was incorrect.  Of course, this should be the SPRF flag.  The code example wiill need to be altered in two places to correct this error.  I apologise for any inconvenience this may have caused.
 
Regards,
Mac
 
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Thank you Mac.
I thought that was it too.
So I went ahead and changed the flag.
Let me try and see if I have any luck tonight.
 
FWFan.
0 Kudos
Reply

2,777 Views
FWFan
Contributor III
Wow, thanks you guys.
I will give this a try soon.
Much appreciated for your quick replys.
I have been trying this SPI stuff for awhile now but no luck.
 
In any case, many thanks again.
FWFan
0 Kudos
Reply