SPI Master doesn't work correctly.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello everybody,

   

At the moment I try out to send a SPI message (Projekt "testendesDAC")

   

I want to use SPI in my current Projekt. But I have Problems to send out a full 16-Bit message. At the moment I send out only 4-Bit. See picture 004.png.

   

Far days away I controlled an ADC with SPI and everthing work fine. See picture 001.png.

   

My hardware: I have develped my own board. The board have got the size of "mbed". It have got an external 24-MHZ Crystal. 

   

Thanks everybody for your help.

   

Regards,

   

Flo 

   

 

   

Scope pics:

   

CH1 - Yellow = CS

   

CH2 - Green = SCLK

   

CH3 - Pink   = MOSI

   

CH4 - Blue  = MISO

0 Likes
18 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you go to the start page, "File", "Example Project", you can pick

   

a working SPIM project to try out. And modify as you wish.

   

 

   

Regards, Dana.

   

 

   

0 Likes
Anonymous
Not applicable

Try using the IMO and PLL to generate the 24M required, see if this helps.

   

you can also try to write the ouput in a endless loop as well. this would make it easier to check. 

0 Likes
Anonymous
Not applicable

I mean continously outputing with the SPI inside a loop, of couse, all some delay inside some can capture the pulses easier.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

first thanks to everybody for your replies. I think I have got a general problem because the UART doesnt't work correctly, too.

   

I implemented a UART and send out data with UART_1_PutArray(). But the device sending out the data correctly. See the picture 004. The UART should put more databits out. So I don`t know where´s the mistake is. A few days ago it was very easy to implemented a UART/SPI.

   

In the attach is the scope picture 005. And the programm to testing  UART. This project was the SPI example projekt. The SPI didn't work today, too. I tried out your answers: For example I changed the clock to PLL/Internal Clock. But I get the same results as yesterday.

   

Regards,

   

Flo

0 Likes
Anonymous
Not applicable

* Picture 005

0 Likes
Anonymous
Not applicable

*And I test the program with different hardware. For example CY(CKIT-050 PSoC 5LP Development Board.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

What makes you think that none of the components uses interrupts?

   

Generally speaking: I suggest you to enable global interrupts as a standard and only disable them when explicitely wanted.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello.

   

That is correct, in my posted project I don't use CyGlobalInterruptEnable.

   

But normally I had use this function. So I don´t think that is the problem.

   

A few minutes ago I add the function to a simple UART projekt. transmit with: UART_1_PutChar(0xAA); (And UART ony send out 3 bits. (002.jpf). And I got the same bad result as before.

   

Thanks everbody for your help!

   

flo

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I modified your project as follows -

   

 

   

1) uart array declared as "const", PutArray wants array to be that

   

2) uart pin to P4_0, initial output state to 0

   

3) Enabled global interrupts

   

4) Eliminated 2'ond for(;;) loop

   

5) Eliminated your startup delay

   

 

   

Works fine on my -050 board.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

okay thanks everybody für your help. I don't know where the problem is. At the moment I try out the UART again and everything works fine. But I have got another Hardware:

   

- Cy8CKIT-042 PSoC 4 Pioneer Kit

   

- Annother Computer

   

See Attach there is my program I had wrote a few minutes ago. UART work. I try this programm tommorow with the previous hardware

   

I want be snooty but:

   

At the moment I do a internship...

   

I work the last weeks with UART every day, from monday to friday and minimum six hours. I wrote a program to listen a Bus and send it out to CAN. I wrote a program to send out UART messages include change the clock of UART. I controlled an ADC with SPI. I controlled a DAC with SPI. Everything works.

   

But from one moment to the other: I couldn't send out UART messages. I couldn't send out SPI messages. And I used the same programs as before.

   

(Receive UART Messages works :-))

   

So, yes I'm not a expert but I think that the problem is not a easy. 

   

- Maybe something with the clock.

   

I know that I did mistakes in my example projects. But I have time at work so normally I find issus like:

   

- Forget CyGlobalInterruptEnable.

   

- Forget to start the Component.

   

So, I try it out tomorrow again and I will post my results.

   

Thanks Dana for your time to modified my program.

   

Regards,

   

Flo

0 Likes
Anonymous
Not applicable

Hi flo,

   

you mentioned in you previous post

   

"A few minutes ago I add the function to a simple UART projekt. transmit with: UART_1_PutChar(0xAA); (And UART ony send out 3 bits. (002.jpf). And I got the same bad result as before."

   

the waveforrm is correct. If you draw the waveform on a piece of paper, you should be able confirm that. Or if you change the  UART to have the tx_clk/rx_clk output and sent it out to a output pin on the psoc. you should be able to see the uart clock together with the serial data. remember that LSB frist. There are 4 ONE in the packet, the last ONE(MSB) is joined with the stop bit. so you should only see 3 pulse.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I tried this out on PSOC 4, some changes -

   

 

   

1) Variables that either were single letters or looked like potential reserved

   

words I changed their name.

   

 

   

2) The Rx flag was declared volatile

   

 

   

3) The Tx data sent restricted to ascii chars

   

 

   

I got it to work, by monitoring my var charrecv,  except I cannot see Tx data on pin, really strange.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello everybody again,

   

I think my mistake was that I'm to dummy to control a scope. And maybe I´m to dummy to write a correct UART program, too.

   

Today I try my last posted project (or look at danaaknight post before this post) with my own Cypress 5LP board. Everythink looks good include the scope pictures. So I create a simular project with SPI. And everythink look include scope picture.

   

See picture 007.png with yellow = ss (chip select), green = clock, blue = MOSI. 

   

In this picture I sent out 0x01.

   

@HL thanks for your answer maybe I lose the track of at trying out the UART yesterday. But I got some scope pictures who look wrong, too. But it could be a scope error (I maybe controlled scope false). In my newest project I read my send out data back with an SPI Slave or an UART RX compment. So I could check my sending out data with scope and the read back compoment.

   

@Dana thank you very much. Maybe it is better to work with two connected input and output ports. And split the direct intern connection between UART TX and UART RX. 

   

Thanks that you modified my project. But I have one question:

   

Why have you changed the flag variable to volatile. What is the advantage? This question I had asked me weeks ago, too. Without an result.

   

Thank you everybody again!

   

Regards,

   

Flo

   

Attach file: Working SPI project and the scope result of one cicle 007.png

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@Dana

   

Didn't work for me as well. I deleted the pin and inserted a new one, now working.

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

"volatile" is telling the compiler that the variable may be altered from "outsides". An IO-port is a classical candidate, but variables changed within an interrupt handler as well.

   

This has to do with optimization that would allow the compiler to remove assignments out of a loop then the right-side expression is not changed within the loop. A dramatical mis-assumption when a port is concerned. So all io-registers are declared to be volatile and this should be done with all variables that are changed in interrupt handlers.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some additional info on Volatile -

   

 

   

    

   

          

   

http://en.wikipedia.org/wiki/Volatile_variable

   

 http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword

   

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@Dana

   

Before changing your project, wouldn't it be worth a try to send it to Cypress for analyzing what's going wrong? I did not find the lightest clue what hinders the pin to work correctly and as far as I remember I had a similar issue some time ago, was fixed by re-creating the project schematic.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you Dana and Bob for your information about volatile.

   

I will use this in project for my external UART and CAN interrupt flag. I don't have problems now but maybe in the future.

   

Regards,

   

Flo

0 Likes