Reading and Writing data to EEPROM of external microcontroller

Hi can anyone help me with this. I want to read and write data to the EEPROM of an external microcontroller using SPI interface. However my code is not working.

#include <SPI.h>

int ss = 10;
// set slaveselect as pin 10
int firstbyte;
SPISettings settingsA(1000000, MSBFIRST, SPI_MODE1);

void setup() {
Serial.begin(9600);
pinMode(ss, OUTPUT);
//set slave select as ardiuno output

SPI.setClockDivider(SPI_CLOCK_DIV8);
//Sets clock for SPI communication at 8 (16/8=2Mhz)
}

void loop() {
SPI.begin();
//To begins the SPI commnuication
SPI.beginTransaction(settingsA);

digitalWrite (ss, LOW);
// set to low for writing
delay (200);
SPI.transfer(0xC0);
// Command to write byte to EEPROM
SPI.transfer16(0x0001);
// 16-bit address location in eeprom (write)
SPI.transfer16(0xAA);
// data. content to write
digitalWrite(SS,HIGH);

digitalWrite(SS,LOW);
SPI.transfer(0xA0);
//Command to read byte from EEPROM
firstbyte = SPI.transfer16(0x0001);
digitalWrite(SS,HIGH);

Serial.println(firstbyte,HEX);

SPI.endTransaction();
delay(200);

}

if you want help from the forum, it would be an idea to provide some basic details of your setup, remember the forum does not know.

Which Arduino ?

Which EEPROM ?

What connections do you have between Arduino and EEPROM ?

What does 'not working' mean ?

Hi sorry, this is my first time using the forum.

I am using Arduino UNO to access the EEPROM memory of an external microcontroller(ATmega328p) using the SPI interface. Hence the connection between the Arduino and the external microcontroller is just, MOSI, MISO, SS, SCK, VCC and GND.
What I am trying to do is:
-I will write one value to one address on the EEPROM
-Then I will read the content of that address from the EEPROM and print out the content

I have been trying for a couple of weeks and I couldn't get the output content that I want.

You need to program your 328p to act as an SPI slave device. You can then write code for the slave 328p to interact with its EEPROM.

markd833:
You need to program your 328p to act as an SPI slave device. You can then write code for the slave 328p to interact with its EEPROM.

Hi thank you for your reply. May I ask do I have to update some firmware to make the 328p act as an SPI slave device?

chewct:
Hi thank you for your reply. May I ask do I have to update some firmware to make the 328p act as an SPI slave device?

You would need to write a program for the 328P to make it act as a SPI slave. Then you would need to write code to read the 328P EEPROM and pass the contents across in the SPI reads.
Google 'Arduino as spi slave' for some tips.
Seems a lot of bother.

chewct:
Hi can anyone help me with this. I want to read and write data to the EEPROM of an external microcontroller using SPI interface. However my code is not working.

Could you please provide a broader picture of your setup and your goals? Why do you need to read EEPROM from another Atmega328. BTW Arduino UNO mainly just is a Atmega 328 by itself.