- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey guys!
I tried to get SPI working. Sadly, I have no clock and slave select also doesn't go low. I have no more ideas how to get this working 😞
I have the pins on the right ports and I got this code:
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include <project.h>
#include "shared_vars_switching.h"
#include "isr.h"
#include "defines.h"const uint16_t n_ticks_per_interval = 2000;
const uint16_t n_ticks_zx_delay = 500;
int16_t duty_cycle[2] = {1000, 0};
int16_t enabled_channels = 1;int16_t tick_delta[4];
int16_t tick_channel[4];
int16_t n_tick_events = 0;int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
/* initialize switching isr */
// isr_switch_Start();
// isr_switch_SetVector(isr_switch_handle);
// isr_switch_SetPriority(0);
//
// isr_zx_Start();
// isr_zx_SetVector(isr_zx_handle);
// isr_zx_SetPriority(0);
//
// tmr_switch_Start();
// tmr_switch_WriteCompare(UINT16_MAX);
/* set metering mode */
CyPins_ClearPin(meter_mmd0);
CyPins_SetPin(meter_mmd1);
/* set up SPI */
//spi_ClearMasterInterruptSource(spi_INTR_MASTER_SPI_DONE);
//spi_SpiSetActiveSlaveSelect(spi_SPI_SLAVE_SELECT0);
//spi_SpiSetSlaveSelectPolarity(spi_SPI_SLAVE_SELECT0, spi_SPI_SS_ACTIVE_LOW);
spi_Start();
isr_spi_Start();
isr_spi_SetVector(isr_spi_handle);
isr_spi_SetPriority(3);
int toggle = 0;
CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
while(1)
{
spi_SpiUartWriteTxData(ADDR_STATUS);
CyDelay(1000);
toggle ^= 1;
if(toggle){
CyPins_SetPin(meter_LED);
}
else{
CyPins_ClearPin(meter_LED);
}
/* Place your application code here. */
}
}/* [] END OF FILE */
The pins for SPI are on SPI[0].
Thanks for any help!!
Peace Noah
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Noah
It is much more easier for us to follow our questions when you upload the complete project archive. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for your answers!
The problem is that the SPI master only has CS low and a clock when it transmits stuff, then pulls it high, effectively disabling the slave to send any data back. Dunno what's the point of this behavior. It's completely useless tbh.
Peace Noah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An SPI slave does not send data back. You have to send dummy data from the master to receive back information from the slave.
Have a look into the SPI datasheet that explains that.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! I didn't know that, I am sorry. I also can't find it explained in the DS at all ... I will dig further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The DS should explain how a SPI master does a read, there you see the steps. Also, the data sheet of the part that you are talking to should explain that as well (tyically there is a timing diagram with CLK, MISO and MOSI).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At least the DS that is attached to the component in the creator does NOT explain that. And not only that, NO example from Cypress explains how to get data back from the slave. They only explain how to write the buffers ...
Actually the example from bobgoar woulda told me that I have to send/receive dummy data. But I didn't understand that fully at first because there was a lot of code for an example I first thought should be really easy to do .
The Also in the ATM90E26 DS it has the timings etc. but that does not explain that I have to tell the master to send dummy data to receive something back.
Maybe there was some master option to say stl like SPIM_spi_fetch_bytes_from_slave(2); and then it does it for me, who knows.
Anyways, I figured how this all works with help of Wikipedia now, after the tip from Bob Marlowe that I have to send dummy data 🙂
I am sorry for not properly reading the here provided example and thank you all for the help 🙂
Peace Noah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are right, the SPI master DS doesn't explain this explicitly (when I get a change for DS feedback I will ask for this to be added). Rather, its kind of hidden in the block diagram and the timing sheets.
But the ATM90E26 DS shows it: chapter 4, figure 3 "read sequence" shows exactly that you need to have clock pulses for 3 bytes, and for the last 2 the ATM90E26 doesn't care what the master sends.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure I know I need to clock. But I can't smell that I have to do it with dummy data and there is no functions ... 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Noah, no excuses needed. I have some reasons why I do not like SPI and prefer other interfaces 😉 and the "dummy bytes" is only one of them.
Bob
PS: Are you going to visit Cypress at the "embedded world" fair in Nürnberg?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your patience with my stupidity 🙂 I managed to get SPI running fine with the chip also responding. Sadly now interrupts are just broken 😄 Guess I will keep posting ...
No, I guess I wont be attending it since it's quite a trip from Switzerland and the semester will start soon ...
Peace