Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #include <stdio.h>
29 #include "bcm2835.h"
30 #include "S25FL204K.h"
31 #include "SPI.h"
32 
33 int main(void)
34 {
35  SPI_Initialize(); //Initialize SPI peripheral
36  S25FL_Setup(); //Setup flash memory
37  S25FL_SReg_Write(0x00); //Remove protection from all blocks writes to SR1
38 
39  printf("NOR Flash memory demo.\r\n");
40  printf("This example will read the chip factory ID \r\n and display the contents of the status registers.\r\n");
41 
42  unsigned int id = S25FL_ReadID(); //read id - 0x01 ox16
43  printf("Manufacturer id: %d \n",id);
44  unsigned long a = S25FL_Jedec_ID_Read(); //0x01 0x40 0x17
45  printf("Jedec ID: %ld \n",a);
46 
47  unsigned char cell = S25FL_SReg_Read(STAT_REG1);
48  printf("Status register one: 0x%02X \n",cell);
49  cell = S25FL_SReg_Read(STAT_REG2);
50  printf("Status register two: 0x%02X \n",cell);
51  cell = S25FL_SReg_Read(STAT_REG3);
52  printf("Status register three: 0x%02X \n",cell);
53 
54  printf("End of demo.");
55  SPI_Close(); //Close SPI peripheral
56 
57 return 0;
58 }
59 
S25FL204K driver header.
void S25FL_Setup(void)
Setup SPI and IOs connected to Serial FLASH.
Definition: S25FL204K.c:39
unsigned int S25FL_ReadID(void)
This function reads the Manufacturer ID code This procedure Reads the manufacturer's ID and device ID...
Definition: S25FL204K.c:156
void SPI_Initialize(void)
Initializes the SPI peripheral.
Definition: SPI.c:35
#define STAT_REG3
Definition: S25FL204K.h:71
void SPI_Close(void)
Close SPI bus, should not be called if another SPI device is being used.
Definition: SPI.c:95
void S25FL_SReg_Write(unsigned char statReg)
This procedure writes a byte to the Status Register.
Definition: S25FL204K.c:279
int main(int argc, char **argv)
Definition: main.c:34
unsigned char S25FL_SReg_Read(unsigned char statReg)
Read specific Status Register depending on value of statReg.
Definition: S25FL204K.c:264
#define STAT_REG1
Definition: S25FL204K.h:69
SPI driver header.
unsigned long S25FL_Jedec_ID_Read(void)
This procedure Reads the manufacturer's ID (BFh), memory type (25h) and device ID (4Bh)...
Definition: S25FL204K.c:177
#define STAT_REG2
Definition: S25FL204K.h:70