How to use AT24C256 module with Shakti Processor?

  • Post author:
  • Reading time:21 mins read
  • Post category:Tutorials
You are currently viewing How to use AT24C256 module with Shakti Processor?

The AT24C256 provides 256kbits of serial, electrically erasable and programmable read-only memory (EEPROM) organized as 32,768 words [8 bits each]. The device’s cascadable feature allows up to 4 devices to share a common Two-wire bus. The device is optimized for use in many industrial and commercial applications where low power and low voltage operations are essential. 

Fig. AT24C256

Protocol:   

Here, I2C protocol is used.

Fig. AT24C256

Main Features:

Manufacturer:Microchip
Product Category:EEPROM
Interface Type:2-Wire, I2C
Memory Size:256 kbit
Organisation:32 k x 8
Brand:Microchip Technology / Atmel
Operating Supply Voltage:1.8 V, 2.7 V
Product Type:EEPROM
Subcategory:Memory & Data Storage

Step 1: What You Will Need

  • Arty7 35t/100t board with either pinaka, parashu or vajra programmed
  • AT24C256.
  • Micro USB Cable.
  • Jumper Wires.
  • shakti-sdk and shakti-tools installed or Platform IO installed and ready

Note: shakti-sdk and shakti-tools are currently a private repository. Please login or sign up to Gitlab and request access here before using it.

Step 2: The Circuit

Connection of AT24C256 sensors,

  • VCC connect to +2.5V to +6V
  • GND to GND
  • SCL to SCL
  • SDA to SDA
Fig. The Circuit diagram of AT24C256 with Arty100t

Step 3: Code

Please click here to have a look at the code of AT24C256.


Code can be compiled and run using the following ways,


Step 4.1: Manual Method

4.1.1 Compile and build

  • Move to shakti-sdk
cd shakti-sdk
  • Compile using make software PROGRAM=? TARGET=?. Type make list_applns to list all the applications available in the SDK. Target can be either parashu, pinaka or vajra.

For instance, Use target as parashu,

make software PROGRAM = at24c256 TARGET=parashu

4.1.2 Execution:

Once the application is built, the executable is generated in the output folder. The executable is in ELF file format and they have the extension .shakti. Now, open three terminals, one for each of the following,

  • One terminal for UART terminal display (miniterm)
  • Another for GDB server
  • And the last one for OpenOCD.

Terminal 1: Firstly Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.

For instance,

$ sudo miniterm.py /dev/ttyUSB1 19200

Note:

  • “/dev/ttyUSB1” – ttyUSB means “USB serial port adapter”
  • The “1” (“0” or “1” or “2”“here means the USB device number on your system. The FPGA board is connected to that USB device number.

Terminal 2: After that, Connect to the FPGA board by using the OpenOCD provided by shakti-tools and its respective configuration file.  (Read how OpenOCD and RISC-V GDB work together to establish a connection between our PC and the Microprocessor)

For instance, if we use parashu,

$ cd shakti-sdk
$ cd ./bsp/third_party/parashu
$ sudo $(which openocd) -f ftdi.cfg

For pinaka and vajra, Goto cd ./bsp/third_party/<pinaka or vajra>


Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e riscv32-unknown-elf-gdb or riscv64-unknown-elf-gdb respectively from shakti-tools.

The output executable is created in <path-to-shakti-sdk>/software/examples/i2c_applns/at24c256/output as at24c256.shakti. Load up the .shakti file by following the below steps,

$ riscv32-unknown-elf-gdb
(gdb) set remotetimeout unlimited
(gdb) target remote localhost:3333
(gdb) file path/to/executable
(gdb) load
(gdb) c

4.1.3 Upload to flash

Steps to generate standalone user application:

The SHAKTI-SDK has a uploader tool that is used to load a content (such as ELF) to flash, after building the image.

  • Goto the right directory.
    cd shakti-sdk
  • The make upload command is used to build and upload the application to the flash automatically.
make upload PROGRAM = at24c256 TARGET=parashu

PROGRAM is the new bare metal user application that is created. Type make list_applns to list all the applications available in the SDK.

Step 4.2: Using Platform IO

We can use IDE’s like Platform IO to compile, build, run, upload and debug. Please read the article on Platform IO on SHAKTI to understand the steps.


Miniterm Output

--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---                  ((                                          
                                    ,(((((
                                *((((((
                           ./(((((((
                       ./((((((((
                    *(((((((((
                .(((((((((((
             ,((((((((((((
           ((((((((((((((
          .((((((((((((((
              *(((((((((((
                   /(((((((
                  *((((((((
                     *(((((((
                       (((((((((
                        ((((((((((
                         (((((((((((((
                         ((((((((((((((
                        ((((((((((((
                      *(((((((((( 
                    (((((((((               
              *(((((((
           *((((((
       .(((((
   ./(((  
SHAKTI PROCESSORS 
 Booting… vspi1.0
 Booting on Parashu! hart 0 
 Parashu is a SoC build on top of Artix7 100T.
 The core belongs to Shakti E class, 32 bit.
 Supported ISA: RV32ACIMNU.
 Processor Arch ID: 0.
 Device ID 1 
 extracted device id 2018 
 …………….
 Control transferred to RAM
 Values are not equal. RV: 55; WV: 0
 Values are not equal. RV: 55; WV: 0
 Control: 80808080; Status: 81818181    I2C Initialization success
     I2C Intilization Success
 AT24C256 EEPROM RW Failed; RV: 0; WV: 55
  Write Value: 0
  Write Value: 1
  Write Value: 2
  Write Value: 3
  Write Value: 4
  Write Value: 5
  Write Value: 6
  Write Value: 7
  Write Value: 8
  Write Value: 9
  Write Value: a
  Write Value: b
  Write Value: c
  Write Value: d
  Write Value: e
  Write Value: f
  Write Value: 10
  Write Value: 11
  Write Value: 12
  Write Value: 13
  Write Value: 14
  Write Value: 15
  Write Value: 16
  Write Value: 17
  Write Value: 18
  Write Value: 19
  Write Value: 1a
  Write Value: 1b
  Write Value: 1c
  Write Value: 1d
  Write Value: 1e
  Write Value: 1f
  Write Value: 20
  Write Value: 21
  Write Value: 22
  Write Value: 23
  Write Value: 24
  Write Value: 25
  Write Value: 26
  Write Value: 27
  Write Value: 28
  Write Value: 29
  Write Value: 2a
  Write Value: 2b
  Write Value: 2c
  Write Value: 2d
  Write Value: 2e
  Write Value: 2f
  Write Value: 30
  Write Value: 31
  Write Value: 32
  Write Value: 33
  Write Value: 34
  Write Value: 35
  Write Value: 36
  Write Value: 37
  Write Value: 38
  Write Value: 39
  Write Value: 3a
  Write Value: 3b
  Write Value: 3c
  Write Value: 3d
  Write Value: 3e
  Write Value: 3f
  Write Value: 40
  Write Value: 41
  Write Value: 42
  Write Value: 43
  Write Value: 44
  Write Value: 45
  Write Value: 46
  Write Value: 47
  Write Value: 48
  Write Value: 49
  Write Value: 4a
  Write Value: 4b
  Write Value: 4c
  Write Value: 4d
  Write Value: 4e
  Write Value: 4f
  Write Value: 50
  Write Value: 51
  Write Value: 52
  Write Value: 53
  Write Value: 54
  Write Value: 55
  Write Value: 56
  Write Value: 57
  Write Value: 58
  Write Value: 59
  Write Value: 5a
  Write Value: 5b
  Write Value: 5c
  Write Value: 5d
  Write Value: 5e
  Write Value: 5f
  Write Value: 60
  Write Value: 61
  Write Value: 62
  Write Value: 63
  Write Value: 64
  Write Value: 65
  Write Value: 66
  Write Value: 67
  Write Value: 68
  Write Value: 69
  Write Value: 6a
  Write Value: 6b
  Write Value: 6c
  Write Value: 6d
  Write Value: 6e
  Write Value: 6f
  Write Value: 70
  Write Value: 71
  Write Value: 72
  Write Value: 73
  Write Value: 74
  Write Value: 75
  Write Value: 76
  Write Value: 77
  Write Value: 78
  Write Value: 79
  Write Value: 7a
  Write Value: 7b
  Write Value: 7c
  Write Value: 7d
  Write Value: 7e
  Write Value: 7f
  Write Value: 80
  Write Value: 81
  Write Value: 82
  Write Value: 83
  Write Value: 84
  Write Value: 85
  Write Value: 86
  Write Value: 87
  Write Value: 88
  Write Value: 89
  Write Value: 8a
  Write Value: 8b
  Write Value: 8c
  Write Value: 8d
  Write Value: 8e
  Write Value: 8f
  Write Value: 90
  Write Value: 91
  Write Value: 92
  Write Value: 93
  Write Value: 94
  Write Value: 95
  Write Value: 96
  Write Value: 97
  Write Value: 98
  Write Value: 99
  Write Value: 9a
  Write Value: 9b
  Write Value: 9c
  Write Value: 9d
  Write Value: 9e
  Write Value: 9f
  Write Value: a0
  Write Value: a1
  Write Value: a2
  Write Value: a3
  Write Value: a4
  Write Value: a5
  Write Value: a6
  Write Value: a7
  Write Value: a8
  Write Value: a9
  Write Value: aa
  Write Value: ab
  Write Value: ac
  Write Value: ad
  Write Value: ae
  Write Value: af
  Write Value: b0
  Write Value: b1
  Write Value: b2
  Write Value: b3
  Write Value: b4
  Write Value: b5
  Write Value: b6
  Write Value: b7
  Write Value: b8
  Write Value: b9
  Write Value: ba
  Write Value: bb
  Write Value: bc
  Write Value: bd
  Write Value: be
  Write Value: bf
  Write Value: c0
  Write Value: c1
  Write Value: c2
  Write Value: c3
  Write Value: c4
  Write Value: c5
  Write Value: c6
  Write Value: c7
  Write Value: c8
  Write Value: c9
  Write Value: ca
  Write Value: cb
  Write Value: cc
  Write Value: cd
  Write Value: ce
  Write Value: cf
  Write Value: d0
  Write Value: d1
  Write Value: d2
  Write Value: d3
  Write Value: d4
  Write Value: d5
  Write Value: d6
  Write Value: d7
  Write Value: d8
  Write Value: d9
  Write Value: da
  Write Value: db
  Write Value: dc
  Write Value: dd
  Write Value: de
  Write Value: df
  Write Value: e0
  Write Value: e1
  Write Value: e2
  Write Value: e3
  Write Value: e4
  Write Value: e5
  Write Value: e6
  Write Value: e7
  Write Value: e8
  Write Value: e9
  Write Value: ea
  Write Value: eb
  Write Value: ec
  Write Value: ed
  Write Value: ee
  Write Value: ef
  Write Value: f0
  Write Value: f1
  Write Value: f2
  Write Value: f3
  Write Value: f4
  Write Value: f5
  Write Value: f6
  Write Value: f7
  Write Value: f8
  Write Value: f9
  Write Value: fa
  Write Value: fb
  Write Value: fc
  Write Value: fd
  Write Value: fe
  Write Value: ff
 read Value: 0
 read Value: 1
 read Value: 2
 read Value: 3
 read Value: 4
 read Value: 5
 read Value: 6
 read Value: 7
 read Value: 8
 read Value: 9
 read Value: a
 read Value: b
 read Value: c
 read Value: d
 read Value: e
 read Value: f
 read Value: 10
 read Value: 11
 read Value: 12
 read Value: 13
 read Value: 14
 read Value: 15
 read Value: 16
 read Value: 17
 read Value: 18
 read Value: 19
 read Value: 1a
 read Value: 1b
 read Value: 1c
 read Value: 1d
 read Value: 1e
 read Value: 1f
 read Value: 20
 read Value: 21
 read Value: 22
 read Value: 23
 read Value: 24
 read Value: 25
 read Value: 26
 read Value: 27
 read Value: 28
 read Value: 29
 read Value: 2a
 read Value: 2b
 read Value: 2c
 read Value: 2d
 read Value: 2e
 read Value: 2f
 read Value: 30
 read Value: 31
 read Value: 32
 read Value: 33
 read Value: 34
 read Value: 35
 read Value: 36
 read Value: 37
 read Value: 38
 read Value: 39
 read Value: 3a
 read Value: 3b
 read Value: 3c
 read Value: 3d
 read Value: 3e
 read Value: 3f
 read Value: 40
 read Value: 41
 read Value: 42
 read Value: 43
 read Value: 44
 read Value: 45
 read Value: 46
 read Value: 47
 read Value: 48
 read Value: 49
 read Value: 4a
 read Value: 4b
 read Value: 4c
 read Value: 4d
 read Value: 4e
 read Value: 4f
 read Value: 50
 read Value: 51
 read Value: 52
 read Value: 53
 read Value: 54
 read Value: 55
 read Value: 56
 read Value: 57
 read Value: 58
 read Value: 59
 read Value: 5a
 read Value: 5b
 read Value: 5c
 read Value: 5d
 read Value: 5e
 read Value: 5f
 read Value: 60
 read Value: 61
 read Value: 62
 read Value: 63
 read Value: 64
 read Value: 65
 read Value: 66
 read Value: 67
 read Value: 68
 read Value: 69
 read Value: 6a
 read Value: 6b
 read Value: 6c
 read Value: 6d
 read Value: 6e
 read Value: 6f
 read Value: 70
 read Value: 71
 read Value: 72
 read Value: 73
 read Value: 74
 read Value: 75
 read Value: 76
 read Value: 77
 read Value: 78
 read Value: 79
 read Value: 7a
 read Value: 7b
 read Value: 7c
 read Value: 7d
 read Value: 7e
 read Value: 7f
 read Value: 80
 read Value: 81
 read Value: 82
 read Value: 83
 read Value: 84
 read Value: 85
 read Value: 86
 read Value: 87
 read Value: 88
 read Value: 89
 read Value: 8a
 read Value: 8b
 read Value: 8c
 read Value: 8d
 read Value: 8e
 read Value: 8f
 read Value: 90
 read Value: 91
 read Value: 92
 read Value: 93
 read Value: 94
 read Value: 95
 read Value: 96
 read Value: 97
 read Value: 98
 read Value: 99
 read Value: 9a
 read Value: 9b
 read Value: 9c
 read Value: 9d
 read Value: 9e
 read Value: 9f
 read Value: a0
 read Value: a1
 read Value: a2
 read Value: a3
 read Value: a4
 read Value: a5
 read Value: a6
 read Value: a7
 read Value: a8
 read Value: a9
 read Value: aa
 read Value: ab
 read Value: ac
 read Value: ad
 read Value: ae
 read Value: af
 read Value: b0
 read Value: b1
 read Value: b2
 read Value: b3
 read Value: b4
 read Value: b5
 read Value: b6
 read Value: b7
 read Value: b8
 read Value: b9
 read Value: ba
 read Value: bb
 read Value: bc
 read Value: bd
 read Value: be
 read Value: bf
 read Value: c0
 read Value: c1
 read Value: c2
 read Value: c3
 read Value: c4
 read Value: c5
 read Value: c6
 read Value: c7
 read Value: c8
 read Value: c9
 read Value: ca
 read Value: cb
 read Value: cc
 read Value: cd
 read Value: ce
 read Value: cf
 read Value: d0
 read Value: d1
 read Value: d2
 read Value: d3
 read Value: d4
 read Value: d5
 read Value: d6
 read Value: d7
 read Value: d8
 read Value: d9
 read Value: da
 read Value: db
 read Value: dc
 read Value: dd
 read Value: de
 read Value: df
 read Value: e0
 read Value: e1
 read Value: e2
 read Value: e3
 read Value: e4
 read Value: e5
 read Value: e6
 read Value: e7
 read Value: e8
 read Value: e9
 read Value: ea
 read Value: eb
 read Value: ec
 read Value: ed
 read Value: ee
 read Value: ef
 read Value: f0
 read Value: f1
 read Value: f2
 read Value: f3
 read Value: f4
 read Value: f5
 read Value: f6
 read Value: f7
 read Value: f8
 read Value: f9
 read Value: fa
 read Value: fb
 read Value: fc
 read Value: fd
 read Value: fe
 read Value: ff
  wv: 0; rv: 0
  wv: 1; rv: 1
  wv: 2; rv: 2
  wv: 3; rv: 3
  wv: 4; rv: 4
  wv: 5; rv: 5
  wv: 6; rv: 6
  wv: 7; rv: 7
  wv: 8; rv: 8
  wv: 9; rv: 9
  wv: a; rv: a
  wv: b; rv: b
  wv: c; rv: c
  wv: d; rv: d
  wv: e; rv: e
  wv: f; rv: f
  wv: 10; rv: 10
  wv: 11; rv: 11
  wv: 12; rv: 12
  wv: 13; rv: 13
  wv: 14; rv: 14
  wv: 15; rv: 15
  wv: 16; rv: 16
  wv: 17; rv: 17
  wv: 18; rv: 18
  wv: 19; rv: 19
  wv: 1a; rv: 1a
  wv: 1b; rv: 1b
  wv: 1c; rv: 1c
  wv: 1d; rv: 1d
  wv: 1e; rv: 1e
  wv: 1f; rv: 1f
  wv: 20; rv: 20
  wv: 21; rv: 21
  wv: 22; rv: 22
  wv: 23; rv: 23
  wv: 24; rv: 24
  wv: 25; rv: 25
  wv: 26; rv: 26
  wv: 27; rv: 27
  wv: 28; rv: 28
  wv: 29; rv: 29
  wv: 2a; rv: 2a
  wv: 2b; rv: 2b
  wv: 2c; rv: 2c
  wv: 2d; rv: 2d
  wv: 2e; rv: 2e
  wv: 2f; rv: 2f
  wv: 30; rv: 30
  wv: 31; rv: 31
  wv: 32; rv: 32
  wv: 33; rv: 33
  wv: 34; rv: 34
  wv: 35; rv: 35
  wv: 36; rv: 36
  wv: 37; rv: 37
  wv: 38; rv: 38
  wv: 39; rv: 39
  wv: 3a; rv: 3a
  wv: 3b; rv: 3b
  wv: 3c; rv: 3c
  wv: 3d; rv: 3d
  wv: 3e; rv: 3e
  wv: 3f; rv: 3f
  wv: 40; rv: 40
  wv: 41; rv: 41
  wv: 42; rv: 42
  wv: 43; rv: 43
  wv: 44; rv: 44
  wv: 45; rv: 45
  wv: 46; rv: 46
  wv: 47; rv: 47
  wv: 48; rv: 48
  wv: 49; rv: 49
  wv: 4a; rv: 4a
  wv: 4b; rv: 4b
  wv: 4c; rv: 4c
  wv: 4d; rv: 4d
  wv: 4e; rv: 4e
  wv: 4f; rv: 4f
  wv: 50; rv: 50
  wv: 51; rv: 51
  wv: 52; rv: 52
  wv: 53; rv: 53
  wv: 54; rv: 54
  wv: 55; rv: 55
  wv: 56; rv: 56
  wv: 57; rv: 57
  wv: 58; rv: 58
  wv: 59; rv: 59
  wv: 5a; rv: 5a
  wv: 5b; rv: 5b
  wv: 5c; rv: 5c
  wv: 5d; rv: 5d
  wv: 5e; rv: 5e
  wv: 5f; rv: 5f
  wv: 60; rv: 60
  wv: 61; rv: 61
  wv: 62; rv: 62
  wv: 63; rv: 63
  wv: 64; rv: 64
  wv: 65; rv: 65
  wv: 66; rv: 66
  wv: 67; rv: 67
  wv: 68; rv: 68
  wv: 69; rv: 69
  wv: 6a; rv: 6a
  wv: 6b; rv: 6b
  wv: 6c; rv: 6c
  wv: 6d; rv: 6d
  wv: 6e; rv: 6e
  wv: 6f; rv: 6f
  wv: 70; rv: 70
  wv: 71; rv: 71
  wv: 72; rv: 72
  wv: 73; rv: 73
  wv: 74; rv: 74
  wv: 75; rv: 75
  wv: 76; rv: 76
  wv: 77; rv: 77
  wv: 78; rv: 78
  wv: 79; rv: 79
  wv: 7a; rv: 7a
  wv: 7b; rv: 7b
  wv: 7c; rv: 7c
  wv: 7d; rv: 7d
  wv: 7e; rv: 7e
  wv: 7f; rv: 7f
  wv: 80; rv: 80
  wv: 81; rv: 81
  wv: 82; rv: 82
  wv: 83; rv: 83
  wv: 84; rv: 84
  wv: 85; rv: 85
  wv: 86; rv: 86
  wv: 87; rv: 87
  wv: 88; rv: 88
  wv: 89; rv: 89
  wv: 8a; rv: 8a
  wv: 8b; rv: 8b
  wv: 8c; rv: 8c
  wv: 8d; rv: 8d
  wv: 8e; rv: 8e
  wv: 8f; rv: 8f
  wv: 90; rv: 90
  wv: 91; rv: 91
  wv: 92; rv: 92
  wv: 93; rv: 93
  wv: 94; rv: 94
  wv: 95; rv: 95
  wv: 96; rv: 96
  wv: 97; rv: 97
  wv: 98; rv: 98
  wv: 99; rv: 99
  wv: 9a; rv: 9a
  wv: 9b; rv: 9b
  wv: 9c; rv: 9c
  wv: 9d; rv: 9d
  wv: 9e; rv: 9e
  wv: 9f; rv: 9f
  wv: a0; rv: a0
  wv: a1; rv: a1
  wv: a2; rv: a2
  wv: a3; rv: a3
  wv: a4; rv: a4
  wv: a5; rv: a5
  wv: a6; rv: a6
  wv: a7; rv: a7
  wv: a8; rv: a8
  wv: a9; rv: a9
  wv: aa; rv: aa
  wv: ab; rv: ab
  wv: ac; rv: ac
  wv: ad; rv: ad
  wv: ae; rv: ae
  wv: af; rv: af
  wv: b0; rv: b0
  wv: b1; rv: b1
  wv: b2; rv: b2
  wv: b3; rv: b3
  wv: b4; rv: b4
  wv: b5; rv: b5
  wv: b6; rv: b6
  wv: b7; rv: b7
  wv: b8; rv: b8
  wv: b9; rv: b9
  wv: ba; rv: ba
  wv: bb; rv: bb
  wv: bc; rv: bc
  wv: bd; rv: bd
  wv: be; rv: be
  wv: bf; rv: bf
  wv: c0; rv: c0
  wv: c1; rv: c1
  wv: c2; rv: c2
  wv: c3; rv: c3
  wv: c4; rv: c4
  wv: c5; rv: c5
  wv: c6; rv: c6
  wv: c7; rv: c7
  wv: c8; rv: c8
  wv: c9; rv: c9
  wv: ca; rv: ca
  wv: cb; rv: cb
  wv: cc; rv: cc
  wv: cd; rv: cd
  wv: ce; rv: ce
  wv: cf; rv: cf
  wv: d0; rv: d0
  wv: d1; rv: d1
  wv: d2; rv: d2
  wv: d3; rv: d3
  wv: d4; rv: d4
  wv: d5; rv: d5
  wv: d6; rv: d6
  wv: d7; rv: d7
  wv: d8; rv: d8
  wv: d9; rv: d9
  wv: da; rv: da
  wv: db; rv: db
  wv: dc; rv: dc
  wv: dd; rv: dd
  wv: de; rv: de
  wv: df; rv: df
  wv: e0; rv: e0
  wv: e1; rv: e1
  wv: e2; rv: e2
  wv: e3; rv: e3
  wv: e4; rv: e4
  wv: e5; rv: e5
  wv: e6; rv: e6
  wv: e7; rv: e7
  wv: e8; rv: e8
  wv: e9; rv: e9
  wv: ea; rv: ea
  wv: eb; rv: eb
  wv: ec; rv: ec
  wv: ed; rv: ed
  wv: ee; rv: ee
  wv: ef; rv: ef
  wv: f0; rv: f0
  wv: f1; rv: f1
  wv: f2; rv: f2
  wv: f3; rv: f3
  wv: f4; rv: f4
  wv: f5; rv: f5
  wv: f6; rv: f6
  wv: f7; rv: f7
  wv: f8; rv: f8
  wv: f9; rv: f9
  wv: fa; rv: fa
  wv: fb; rv: fb
  wv: fc; rv: fc
  wv: fd; rv: fd
  wv: fe; rv: fe
  wv: ff; rv: ff
  I2C test passed