##// END OF EJS Templates
Added Oplayer BSP, Fixed bug on GPIO library(gpiosetval change all the port...
Added Oplayer BSP, Fixed bug on GPIO library(gpiosetval change all the port instead of the desired bit).

File last commit:

r58:dcfec4f56803 dev_alexis
r60:17402611bd25 dev_alexis
Show More
main.c
93 lines | 1.9 KiB | text/x-c | CLexer
#include <stdio.h>
#include <fat32.h>
#include <gpio.h>
#include <uart.h>
#include <stm32f4xx.h>
#include <bsp.h>
#include <core.h>
#include <N25Q128.h>
#include <spi.h>
extern streamdevice* __opnfiles__[];
/*
N25Q128 pinout:
MISO => PB14
MOSI => PB15
SCK => PB13
CS => PB12
WP => PC1
RESET/HOLD => PC2
*/
void cs(int csstate)
{
gpiosetval(PB12,csstate);
}
void wp(int wpstate)
{
gpiosetval(PC1,wpstate);
}
void resetHold(int rhstate)
{
gpiosetval(PC2,rhstate);
}
int main()
{
spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,-1);
//spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,PB12);
gpio_t PC1pin= gpioopen(PC1);
gpiosetdir(&PC1pin,gpiooutdir);
gpio_t PC2pin= gpioopen(PC2);
gpiosetdir(&PC2pin,gpiooutdir);
gpio_t PB12pin= gpioopen(PB12);
gpiosetdir(&PB12pin,gpiooutdir);
gpioset(PC1);
gpioset(PB12);
gpioclr(PC2);
eepromN25Q128Dev eeprom;
eepromN25Q128open(&eeprom,spi2,&cs,&wp,&resetHold);
//eepromN25Q128open(&eeprom,spi2,NULL,&wp,&resetHold);
delay_100us(10);
gpioset(PC2);
gpioclr(PB12);
spiputw(spi2,0x9E);
char res[22];
spigetnc(spi2,res,22);
gpioset(PB12);
for(int i=0;i<22;i++)
{
printf("res[%d] = 0x%x\n\r",i,(int)res[i]);
}
eepromN25Q128enablewrite(&eeprom);
delay_100us(10);
eepromN25Q128writen(&eeprom,0,"hello World",11);
delay_100us(10);
eepromN25Q128readn(&eeprom,0,res,11);
res[11]='\n';
res[12]='\r';
res[13]=0;
printf("read: %s",res);
printf("\n");
for(int i=0;i<11;i++)
{
printf("res[%d] = 0x%x\n\r",i,(int)res[i]);
}
while(1)
{
gpioset(LED3);
delay_100us(10000);
gpioclr(LED3);
delay_100us(10000);
}
printf("hello world\n\r");
return 0;
}