Store an image to SD card via TX pin

Hi everyone

I take photo by camera ov7670 as shown in the following link. Then, I want to store in the SD card. The problem is that the pin 11 which is used as MOSI is not empty.

Is it possible to send data from tx pin of Arduino uno to SD module?

Visual Capturing with cameraOV7670

Thanks in advance.

Is it possible to send data from tx pin of Arduino uno to SD module?

No.

The problem is that the pin 11 which is used as MOSI is not empty.

Why isn't it? Move whatever is using that pin.

Thank you
Would you also please answer my question (the last comment) in the link that I mentioned?

Mahdiyar:
Thank you
Would you also please answer my question (the last comment) in the link that I mentioned?

That question was:

3- How we can understand the data of the photo is stared to be sent. Is there any signaling for this?

That code is using registers defined in the data sheet for the ATMega328 chip to directly write to the serial port and to directly read from and write to the SPI pins. Look at the datasheet for full details.

3- How we can understand the data of the photo is stared to be sent. Is there any signaling for this?

Looking at the code, that is done through

  StringPgm(PSTR("*RDY*"));

1- usually, in the Arduino coding we definitely the ports as input or out put while I couldn’t find any definition about that in the code.

That is done by direct port manipulation. As PaulS said, consult the datasheet as well as the schematic of the Uno. E.g.

DDRB |= (1 << 3);//pin 11

sets pin 11 as output while not touching other pins of port B.

And

while ((PIND & 4));//wait for low

checks if pin 2 is high; as long as it is, it will stay in the while-loop.

Using an SD card on the Arduino will give you some challenges in that project. As far as I can see, write speed is not one that can easily be overcome unless you reduce the 8MHz clock speed which will slow down the capture.

You can write quickly 512 bytes to the buffer, after that a flush will happen that will slow the complete process down and you might miss video data thanks to that.

If you still want to give it a try, below the steps to change the clock from pin 11 to another pin; pin 9 in this case. I did this as an exercise for myself. As far as I can see, you will need to change the below in void arduinoUnoInut(void).

  /* Setup the 8mhz PWM clock
    This will be on pin 11*/
  DDRB |= (1 << 3);//pin 11
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
  TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
  TCCR2B = (1 << WGM22) | (1 << CS20);
  OCR2A = 0;//(F_CPU)/(2*(X+1))

You will need a PWM capable output pin. Options on an Uno are
D11 (OC2A, current)
D10 (OC1B, 16 bit)
D9 (OC1A, 16 bit)
D6 (OC0A)
D5 (OC0B)
D3 (OC2B, in use for vsync)
You also, to my knowledge, need a pin that can do FastPWM which leaves the OCxA pins which leaves you with pin 9 (free) or pin 6 (in use). To use pin 9, these are the steps.

Change this line

DDRB |= (1 << 3);//pin 11

to

DDRB |= (1 << 1);//pin 9

Next you must use timer 1 to toggle pin 9 instead of timer 2 for pin 11
Replace

TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
TCCR2B = (1 << WGM22) | (1 << CS20);
OCR2A = 0;//(F_CPU)/(2*(X+1))

by

TCCR1A = (1 << COM1A0) | (1 << WGM11) | (1 << WGM10);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
OCR1A = 0;//(F_CPU)/(2*(X+1))

You can give this a shot using the serial output first. If it does not work, I can’t help you further.

I have no option to test. I’ve verified that the clock on pin 9 is 8MHz with a separate sketch but there are some glitches that I can’t explain (yet); I’m not planning to spend time on that, it can very well be the equipment that I’m using.

Notes:
1)
Be careful with the error_led (pin 13); that pin will also be used by the SPI interface for the SD card.
2)
For the SD card, you can try to reduce the clock to e.g. 1MHz; the complete readout will be slower but you have a better chance of reading all bytes. You might even have to go lower depending how fast you can write to the card.
3)
Please consult the datasheet to get a better understanding of the code that you’re working with. You can find nearly everything that you’re looking for by searching for e.g. TCCR2A, DDR and UDR.