Mega pin 51 (MOSI) -> SIN (Tlc pin 26)
Mega pin 52 (SCK) -> SCLK (Tlc pin 25)
Mega pin 11 (OC1A) -> XLAT (Tlc pin 24)
Mega pin 12 (OC1B) -> BLANK (Tlc pin 23)
Mega pin 9 (OC2B) -> GSCLK (Tlc pin 18)
According to this: SPI - Arduino Reference, digital pins 50-52 on Arduino Mega are also connected to the pins on the ICSP header.
But I I run this sketch:
The ICSP pins on an arduino are wired to the ISP pins of the AVR, which are in parallel with the hardware SPI interface pins (at least, on all AVRs that are used on Arduinos.) They are NOT always connected to Digital 11..13 !
The ICSP header is connected to the ISP pins on the micro, which are the SPI pins since SPI (serial peripheral interface) is the protocol used to program via ICSP (in-circuit system programming).
As westfw said, you're setting pins 11-13 as OUTPUT, then you're writing to the SPI pins. On an Uno, those happen to be the same physical pins. On the Mega, they're not.
(The whole point of using the ICSP connector for SPI shields like the Ethernet Shield is that they run SPI on all of (Uno, MEGA, Due.) Older shields (older versions of of the ethernet shield, even) connected up D11..13 but still used the SPI peripheral, and that wasn't where SPI WAS on the MEGA. So the original Ethernet shield didn't work on the MEGA, and modern shields are supposed to use the ISP connector if they want to do 'hardware spi.'
Of course, you could do SPI via software bit-banging on pins D11..13 regardless of HW type, but that would usually be slower.
I don't know what the TLC5940 driver that you're using does...)
The schematic shows pretty clearly that the SPI pins on the Mega2560 board do not go to D10..D13. However, much to my chagrin, I discovered this week that the schematic shows all of the INT0..INT5 pins wired to the "wrong" header pins. This killed me for a little while.
Can someone explain why they decided it was necessary to remap the INTx pins so that INT0 would still be on D2 and INT1 would still be on D3, but they didn't care to put SPI on D10..D13?
oric_dan:
The schematic shows pretty clearly that the SPI pins on the Mega2560 board do not go to D10..D13. However, much to my chagrin, I discovered this week that the schematic shows all of the INT0..INT5 pins wired to the "wrong" header pins. This killed me for a little while.
No I hadn't, but otherwise sure enough discovered the interrupts are all remapped on the Mega2560 board. You will also notice pighixxx doesn't mention this on his neato Mega board diagram either.
External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
boylesg:
What sort of things would you use that ICSP header for? Can you give some examples?
First and foremost, for ICSP -- that is, programming the AVR chip from an external programmer. Or, using the Mega AS a programmer FOR another AVR chip.
But also, as a way for shields to reliably know where to find SPI, regardless what physical (on the chip) or digital (in the Arduino lib) pins its implemented on.
External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
They agree with my chart if you count the first number as a "pin on board" number. So pin D19 is indeed "attachInterrupt (4, ...)" however it is not INT4. So that document refers to what you are "supposed to use" not the INTx values. That's why I did the chart, because it is damn confusing if you want to configure the correct registers.
That's what I'm saying. It's confusing no matter what one tries to do. Too bad Ardunio centrale doesn't mention anything about the discrepancy (aka confusion) on the Mega board product page.
I haven't tested this, but just wanted to bring it to your attention, and ask your opinion on whether this will work or not for the Mega2560, with its remapped interrupts.
I am using a library that has the following line in it,
bitClear(EIMSK, INT0);
Given the library, this line assumes INT0 is on D2 because of the remapping, but INT4 is "really" on D2 in actuality. So will the proper bit get cleared in the EIMSK register, or not?
I can test this, but just find the overall logic of such operations to be utterly confusing. Given the following code that appears in WInterrupts.c,
Given the library, this line assumes INT0 is on D2 because of the remapping, but INT4 is "really" on D2 in actuality. So will the proper bit get cleared in the EIMSK register, or not?