<#define SPISettings my_spi> in MAIN SKETCH not linked to functions in separate TABS

Hi,
I am trying to get an RTL8720 to communicate with a Wiz5500 Ethernet module using the SPI bus.
Main code (given just below) as well as two read (read.h) and write (write.h) functions in separate TABS.

#include <SPI.h>
#include "definitions.h"
#include "read.h"
#include "write.h"

#define SPI_HAS_EXTENDED_CS_PIN_HANDLING 1
#define SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed
#define SPI_MODE     'M'

uint16_t address = 0x0000;
byte control = 0b00000100;
byte reg_Data = 0;


void setup() {

   Serial.begin(115200);
   Serial.println("VERSIONR Register Test!"); 
   
   SPI.begin();
   delay(1); 
    
}

void loop() {

  

  Serial.print("VERSIONR Address -- ");
  Serial.println (VERSIONR, HEX);
     
  Serial.print ("CONTROL -- ");
  Serial.println (control);

  Serial.print ("VERSIONR -- ");
  Serial.println (reg_Data);
     
  Serial.println (); Serial.println ();
  
delay(1000);

}

The code in the read.h TAB is given below. write.h has almost same code.

byte read_reg(uint16_t address, byte control,byte reg_Data){
  
if ((control & 0b00000100) != 0b00000000){
  byte Acontrol = control | 0b00000000;
}
     SPI.beginTransaction(PA15,my_spi);

     SPI.transfer16(address);
     SPI.transfer(Acontrol);
     SPI.transfer(reg_Data, SPI_LAST);

     delay(1);
 SPI.endTransaction();
 digitalWrite(PA15, LOW);
      
 return(reg_Data);
}

I am getting the error message copied below i.e. "my_spi not declared in this scope"

C:\Users\M1\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.7\libraries\SPI exit status 1'my_spi' was not declared in this scope

What am I doing wrong. Please help

TIA
azhaque

You don't understand how #define works. It just does a text substitution and you never referenced the #define that set up my_spi. Also it only applies to the file it is in.

Thanks.

So what do I do. Should I remove the #define?

I removed #define but still no joy

Just adding the following 2 statements did the trick and the program compiled.

SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed

byte Acontrol;

byte read_reg(uint16_t address, byte control,byte reg_Data){

SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed
byte Acontrol;

if ((control & 0b00000100) != 0b00000000){
    Acontrol = control | 0b00000000;
}
     SPI.beginTransaction(PA15,my_spi);

     SPI.transfer16(address);
     SPI.transfer(Acontrol);
     SPI.transfer(reg_Data, SPI_LAST);

     delay(1);
 SPI.endTransaction();
 digitalWrite(PA15, LOW);
      
 return(reg_Data);
}
 

Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.