Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

STM32VLDiscovery - SPI read and display of data

Status
Not open for further replies.

orionsbelt

Junior Member level 2
Joined
Mar 6, 2015
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
218
Hello all,

I am quite new to STM32 programing. But i need it for my project.
I am going to transfer data from an accelerometer to STM32VLdiscovery board via SPI. Now I have the code written and uploaded without any error shown.

But I still can not see the data from the accelerometer in real time, even when I am going to the debugging mode and turning on the debug viewer. Where am I doing it wrong?

I also like to save the data into a log file. How do I do that?

I would be glad to get some help from you.

//OB
 

As not all edaboard.com users have a crystal ball at hand - perhaps it'll be a good idea to post your code...
 

Oh I am sorry..I thought that the code file was uploaded! Obviously it wasn't! But here the code that has been written for reading of the SPI. I just connot figure out where and how to display the data from the SPI. I am newbie in STM32 programming.

//Code

#include "stm32f10x_conf.h"
#include "spi.h"
#include <stdio.h>

int main(void) {
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
SPI_InitTypeDef SPI_InitStructure;

SystemInit();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_SPI1, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_WriteBit(GPIOA, GPIO_Pin_4, 1);

NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CRCPolynomial = 0;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_Init(SPI1, &SPI_InitStructure);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);

SPI_Cmd(SPI1, ENABLE);

// EXAMPLE
spi_create(SPI1, GPIOA, GPIO_Pin_4);

while(1) {
spi_read();

}
}

//Code ends
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top