element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development Problems with the SPI on the Zedboard
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 1 reply
  • Subscribers 312 subscribers
  • Views 261 views
  • Users 0 members are here
Related

Problems with the SPI on the Zedboard

Former Member
Former Member over 10 years ago

Hello, i am a newbie in terms programming with the zedboard. I want to communicate with a pmod via spi0 from the PS. My problem is, that the code blocks on the place where i poll the Transmition done flag

while((XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_SR_OFFSET)&0x4)==0)
{
buffer = XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_SR_OFFSET);
}

Buffer is always 0. Can someone of you help me or give me an working exmple?

Is it a problem that i dont use the MIO?






Code:

int ARMSpi4ByteRW( unsigned int unPeripheralAddressSPI, unsigned int* auchWriteBuf, unsigned int* auchReadBuf)
/**
* brief       Perform a fixed 4 byte SPI read/write operation using the selected Cortex A9's SPI peripheral
* par         Details
*              -CPHA and CPOL are set to 0, 0.
*              -Pointers are provided to u8 buffers containing the data to be written and received
*              -Data in the auchWriteBuf will be clocked out (MSB first) onto the MOSI pin
*              -Data from the MISO pin will be placed into the auchReadBuf
*              -SS0 is used for chip select and set to active low
*              -ARM CPU Clock = 600MHz
*              -Peripheral System Clock = 114.287513MHz
*              -SCLK freq is set to = CPU CLK/ DIV = 3.57MHz
*
* param[in]   unPeripheralAddressSPI       - ARM Cortex A9's SPI peripheral address
* param[in]   *auchWriteBuf       ttt- pointer to write data buffer
* param[out]  *auchReadBuf        ttt- pointer to read data buffer
*
* retval      int ttttt        - Always returns 0
*/
{
t//SPI Peripheral Settings
t//Manual Start Command =1 Bit [16]
t//Manual Start Enable = 1 Bit [15]
t//Manual Chip Select = 1 Bit [14]
t//Chip Select Lines => [13:10] 0000 chip select 0 selected, 1111 no chip select selected
t//Make Zero => Bits [9:8]
t//Reserved, => Bits [7:6]
t//Baud rate = clk / 32, => Bits [5:3]
t//CPOL=0 CPHA=1, => Bits [2:1]
t//Enable master mode, => Bit [0]
tunsigned int buffer;

tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_CR_OFFSET,0xFC25);

t//Enable the SPI peripheral, and the SS0 pin goes high
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_ER_OFFSET,0x1);


t//Write a value to the Tx_Data_reg
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_TXD_OFFSET,auchWriteBuf[0]);

t//Write a value to the Tx_Data_reg
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_TXD_OFFSET,auchWriteBuf[1]);

t//Write a value to the Tx_Data_reg
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_TXD_OFFSET,auchWriteBuf[2]);

t//Write a value to the Tx_Data_reg
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_TXD_OFFSET,auchWriteBuf[3]);

t//Assert SS1 pin, SS0 goes low
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_CR_OFFSET,0xC425);

t//start the SPI transaction by writing a 1 to the Man_start_com bit
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_CR_OFFSET,0x1c425);

twhile((XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_SR_OFFSET)&0x4)==0)
t{
ttbuffer = XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_SR_OFFSET);
t}

t//SS1 goes high
tXSpiPs_WriteReg(unPeripheralAddressSPI,XSPIPS_CR_OFFSET,0xFC25);

t//Read the Rx_Data_reg
tauchReadBuf[0]=XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_RXD_OFFSET);

t//Read the Rx_Data_reg
tauchReadBuf[1]=XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_RXD_OFFSET);

t//Read the Rx_Data_reg
tauchReadBuf[2]=XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_RXD_OFFSET);
tauchReadBuf[2]=auchReadBuf[2]<<8;

t//Read the Rx_Data_reg
tauchReadBuf[3]= auchReadBuf[2] + XSpiPs_ReadReg(unPeripheralAddressSPI,XSPIPS_RXD_OFFSET);

treturn 0;
}

  • Sign in to reply
  • Cancel
  • zedhed
    0 zedhed over 10 years ago

    Hi janprignitz,

    Although I don't see anything specifically wrong with what you are doing, I am curious why you are using the lower level calls defined within xspips_hw.h rather than the higher level API defined within xspips.h?

    There are examples of how to use the higher level API within the C:XilinxSDK2014.4dataembeddedswXilinxProcessorIPLibdriversspips_v2_0examples folder.

    Also, since you are not using MIO, have you used an oscilloscope to see that the physical SPI lines are transitioning as you expect them to?  If they are transitioning as expected, that is a good sign that the EMIO has been connected correctly.

    Regards,

    -Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube