AnsweredAssumed Answered

HIGH SPEED GPIO PROBLEM

Question asked by delos_reyes.kristian on Feb 1, 2013
Latest reply on Feb 6, 2013 by delos_reyes.kristian
Hi Guys,

I have a question, I have this code and the TTL logic interface that I am reading has a speed of about 1Us The problem is.. I am not able to read all of the 1Us Data.. do you have suggestions how to tweak my code? for now I am using serial to view my data..as I am just in the process of studying SPI and SDIO
001.#include "stm32f10x.h"
002.#include "stdio.h"
003.#include "stm32f10x_conf.h"
004.#include "stm32f10x_spi.h"
005. 
006.#define BufferSize 32
007.typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
008. 
009. /* function prototypes */
010.void RCC_Configuration(void);
011.void GPIO_Configuration(void);
012.void USART_Initialization(void);
013.void SPI_Initialization(void);
014.void resetDataAndCounter(void);
015.void SendData(void);
016. 
017.  /* structure with data for USART configuration */
018.  USART_InitTypeDef USART_InitStructure; /* HW configuration */
019.  SPI_InitTypeDef SPI_InitStructure;
020.  GPIO_InitTypeDef GPIO_InitStructure;
021.   
022.  SPI_InitTypeDef SPI_InitStructure;
023.  uint8_t SPI_MASTER_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
024.                                            0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
025.                                            0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
026.                                            0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
027.                                            0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
028.                                            0x1F, 0x20};
029.  uint8_t SPI_SLAVE_Buffer_Rx[BufferSize];
030.  __IO uint8_t TxIdx = 0, RxIdx = 0;
031.  volatile TestStatus TransferStatus = FAILED;
032.  ErrorStatus HSEStartUpStatus;
033.   
034. int datas[30];
035. int ctr = 0;
036.  
037. int main(void)
038. {
039.  RCC_Configuration();
040.  GPIO_Configuration();
041.  USART_Initialization();
042.  SPI_Initialization();
043.  resetDataAndCounter();
044. 
045.  while (1)
046.  {
047.     
048.    int PortsData = 15- GPIOA ->IDR >>8 & 0x000F;
049.     
050.    if (PortsData == 10)
051.    {
052.      int DIOData = 255 - GPIOC ->IDR>>0 & 0x00FF;
053.      if ((DIOData > 64)&&(DIOData <=96))
054.      {
055.        datas[ctr] = DIOData;
056.        USART_SendData(USART2, datas[ctr]);
057.      };
058.      ctr++;
059.      while (PortsData !=6)
060.      {
061.        PortsData = 15 - GPIOA ->IDR >>8 & 0x000F;
062.      }
063.    }
064.     
065.    if ((ctr==30))
066.      {
067.        //send DATA;
068.        SendData();
069.        ctr = 0;
070.        resetDataAndCounter();
071.      }
072.  }
073. }
074.  
075. void resetDataAndCounter(void)
076. {
077.    ctr = 0;
078.    for (int ctr1 = 0; ctr1 <30; ctr1++)
079.    {
080.      datas[ctr1] = 0;
081.    }
082. }
083.  
084. void SendData(void)
085. {
086.   for (int ctr1 = 0; ctr1<30; ctr1++)
087.   {
088.    USART_SendData(USART2, datas[ctr1]);
089.    for (int ctr2=0; ctr2<=1024; ctr2++);
090.   }
091.   USART_SendData(USART2,44);
092. }
093.  
094. void RCC_Configuration(void)
095. {
096.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
097.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
098.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
099. }
100.  
101. void GPIO_Configuration(void)
102. {
103.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
104.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
105.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
106.   GPIO_Init(GPIOA, &GPIO_InitStructure);
107.    
108.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; 
109.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
110.   GPIO_Init(GPIOA, &GPIO_InitStructure);
111.    
112.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
113.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
114.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
115.   GPIO_Init(GPIOC, &GPIO_InitStructure);
116.    
117.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ; 
118.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
119.   GPIO_Init(GPIOC, &GPIO_InitStructure);
120. 
121. }
122. void USART_Initialization(void)
123. {
124.  USART_InitStructure.USART_BaudRate = 115200;
125.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
126.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
127.  USART_InitStructure.USART_Parity = USART_Parity_No ;
128.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
129.  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
130.  USART_Init(USART2, &USART_InitStructure);
131.  USART_Cmd(USART2, ENABLE);
132. }
133.  
134. void SPI_Initialization(void)
135. {
136.   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
137.   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
138.   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
139.   SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
140.   SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
141.   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
142.   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
143.   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
144.   SPI_InitStructure.SPI_CRCPolynomial = 7;
145.   SPI_Init(SPI1 , &SPI_InitStructure);
146.   SPI_Cmd(SPI1, ENABLE);
147. }

Outcomes