2013-02-01 07:04 AM
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
#include ''stm32f10x.h''
#include ''stdio.h''
#include ''stm32f10x_conf.h''
#include ''stm32f10x_spi.h''
#define BufferSize 32
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* function prototypes */
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Initialization(void);
void SPI_Initialization(void);
void resetDataAndCounter(void);
void SendData(void);
/* structure with data for USART configuration */
USART_InitTypeDef USART_InitStructure; /* HW configuration */
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
uint8_t SPI_MASTER_Buffer_Tx[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
0x1F, 0x20};
uint8_t SPI_SLAVE_Buffer_Rx[BufferSize];
__IO uint8_t TxIdx = 0, RxIdx = 0;
volatile TestStatus TransferStatus = FAILED;
ErrorStatus HSEStartUpStatus;
int datas[30];
int ctr = 0;
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART_Initialization();
SPI_Initialization();
resetDataAndCounter();
while (1)
{
int PortsData = 15- GPIOA ->IDR >>8 & 0x000F;
if (PortsData == 10)
{
int DIOData = 255 - GPIOC ->IDR>>0 & 0x00FF;
if ((DIOData > 64)&&(DIOData <=96))
{
datas[ctr] = DIOData;
USART_SendData(USART2, datas[ctr]);
};
ctr++;
while (PortsData !=6)
{
PortsData = 15 - GPIOA ->IDR >>8 & 0x000F;
}
}
if ((ctr==30))
{
//send DATA;
SendData();
ctr = 0;
resetDataAndCounter();
}
}
}
void resetDataAndCounter(void)
{
ctr = 0;
for (int ctr1 = 0; ctr1 <30; ctr1++)
{
datas[ctr1] = 0;
}
}
void SendData(void)
{
for (int ctr1 = 0; ctr1<30; ctr1++)
{
USART_SendData(USART2, datas[ctr1]);
for (int ctr2=0; ctr2<=1024; ctr2++);
}
USART_SendData(USART2,44);
}
void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOA, &GPIO_InitStructure);
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;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
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 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void USART_Initialization(void)
{
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
}
void SPI_Initialization(void)
{
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1 , &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}
2013-02-01 07:12 AM
The USART output routines seem to ignore the need to wait on the register to be empty.
2013-02-01 07:24 AM
HI Clive thanks for your update... so there's nothing wrong with my GPIO code? its fully optimized?
ahh this one-USART_SendData(USART2, datas[ctr]); I just Forgot to remove it I was trying to troubleshoot why I can't read the microseconds data and it turns out that I was not able to read it for example the controller sends a ABCDEFG, with the ''the one I forgot to remove'' it is showing sometime A sometime D in other words random I always wait 5 seconds before I send Data.. still same.. all RANDOM is STM32VL capable to read microseconds of TTL logic? I am trying to make it work on VL befor I burn my F42013-02-01 07:36 AM
by the way I've tried this code in debug Mode... I am manually triggering the pins and it is working... wondering y it is not working in actual. though I have verified the signals in scope and in logic analyzer.
2013-02-01 11:38 AM
so there's nothing wrong with my GPIO code? its fully optimized?
Can't say I know enough about the solution to have an opinion. If timing is critical, I'd latch the data externally, and then toggle a pin, or generate an EXTI interrupt.2013-02-05 03:28 PM