Graphicstest where do you assign SPI pins?

I am trying to use an Adafruit 2.8in TFT with capacitive touchscreen on a Mega 2560 board.
I know the SPI pins are different than an Ono so where do I change the SDI pin assignment in the include files??

I am an experienced embedded C programmer as well as an EE of 40 years. I was writing raw SPI drivers long before they were included in the libraries so I know how it works. iust need the location of where these are assigned in the ILI9341 library?

The assignment may be done automatically by the library. It is informed via the Arduino IDE which Arduino board you have chosen, and each has its specific set of definitions for "standard" pins. And of course, you need to physically wire the display to the correct pins.

You usually have some freedom as to which pin is chosen for SS.

Finally, you can always look at the library code.

Well nowhere on the 2560 board or in the PINOUT diagram are SPI pins defined. Somewhere in the code there has to be a processor specific pin assignment for the SPI signals. ANY microcontroller with at least three I/O pins is capable of generating SPI packets.

Hardware specific pins are assigned in the header and config files for the board you select as the target in "Tools|Board" in the IDE.

Here is my C code for a 16bit SPI interface on an Atmel ATMega8 processor. This is not using the Arduino system. SPI is not that hard!

#define VCA_DATA     2  // PORT D1
#define VCA_CLK        4  // PORT D2
#define VCA_CS         32  // PORT C5


vca_out(unsigned char n)  // n = 8bit value to send
{
    unsigned int q,r;

     r= ((n << 8) + n);  // both channels same
     PORTC &= ~(32);  // vca chip select
     for (q= 0x8000; q>= 1; q/= 2)  {
          if (r & q)
              PORTD |= (VCA_DATA);
          else
              PORTD &= ~(VCA_DATA);
          PORTD |= (VCA_CLK);
          PORTD &= ~(VCA_CLK);
        }
       PORTC |= 32;  // vca chip unselect
return;
}

So why are you using a Mega if you don't want to use its hardware features?

How do you want to implement multiple protocols that work concurrently and independently without using the existing controller hardware?

So where is MEGA2560.h or what ever they call it located?

Habit I guess. Multiple protocols? Just write a function as required. Like I do for the serial ports. When I started with 8051s there were no I/O functions pre written. You had a standard K&R C compiler with a relocator for the specific processor and that was it. When I had to use VGA chips, you programmed the registers one by one as needed.

OK, so it's PB0-3. That's all I need to know. Thanks!

I think this is a classic "can't see the forest through though trees" problem on my part.

In an Arduino sketch you deal with board pins, not with controller chip pins.

Again, habit from the old 8048 and 8051 days. I will say the built in SPI functions can run much faster but that is not always necessary.

Not only faster, they also are independent from any other signals (interrupts...). Hardware can receive further data by UART or I2C while you are bit banging SPI. Hardware also can output multiple PWM pulses without dependencies on any other signals.

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