I'm working on a project with an Arduino Mega2560, and another module. To communicate with this module I have two wires, one used by Arduino to provided an external clock to the module, this clock indicates the speed of the IO, and the second wire used as IO half duplex. So far I already made a driver to communicate with that module, but my IO is driven in software which brings some limitation about the speed. To improve this I'd like to reuse the serial USART1 as IO channel and keep the external clock as well (mandatory by the other module). For the moment I'm thinking about the feasibility and I think there is 2 key parts.
The electronic part: RX and TX will share the same wire so i need to put some pull up resistors in place if i'm not wrong. Is it doable ?
The software part: I found that the speed of the USART is computed based on the internal clock of the chip, so in my case 16MHz. But the external clock I want to provide is 1MHz. My question is how can I compute the correct baud rate on Arduino side, if i want to have a clock at 1MHz and a speed at 372 clock pulses for 1 bit transmitted.
Any help is welcome
PS: for this project, I'm not using the Arduino library, I'm playing directly with the registers.
I'm agree the clock as nothing to do with the serial. The idea is to reuse the USART hardware for my IO to have less to manager on software side and be faster. But my other module requires that external clock to know the speed of the IO.
My question is more about how to compute the baudrate on the arduino side to be able to transmit 1bit on a time of 372 clock pulse with a clock at 1MHz but for a clock at 16MHz. Does it mean in case of 16MHz, 1 bit will take 372/16 clock pulse ?
To communicate with this module I have two wires, one used by Arduino to provided an external clock to the module, this clock indicates the speed of the IO, and the second wire used as IO half duplex.
Sounds like SPI to me. A clock line and a data line. I presume you have a third wire? Ground?
If you look at the datasheet the USART can be used in a SPI like mode using a clock signal along with the data signal, but using the serial pins rather then the SPI pins. It's just not something supported by the Arduino API so you would have to role your own library. That's is what the S part of USART means rather then just calling it a UART.
The USART can also be used in Master SPI mode, see “USART in SPI Mode” on page 206. The
PRSPI bit in ”Minimizing Power Consumption” on page 43 must be written to zero to enable SPI
Sorry for the late reply.
Just to resume, I have one Arduino Mega2560 which is linked to a smart card connector. This smart card connector just redirects the contacts of a smart cart to 8 pins. In my case I'm focusing on the IO part. The way to communicate with a smart card is defined in the ISO 7816-3 ISO 7616 part 3 smart card standard. Typically, the Arduino provided an external clock to the smart card to indicate the speed to use to transmit the data. Another wire is used for IO. So far I have one driver on Arduino which handle the communication but it's all in software, meaning managing the external clock + exchanging the bits are done in software, which brings some limitation, I cannot go faster than with a clock at 1MHz.
My idea is to handle my IO in hardware. I know some chip provides an UART hardware ISO 7816-3 compliant but I prefer to try first to solve this without adding any hardware part. My first idea is to reuse one of the hardware USART and trick it to be able to use it with a smartcard. But one problem is the speed, for USART it's related at one point at the internal clock. At first, I don't know why, I was block by SPI, but it seems a better solution and at least a more evident one regarding your comments. One think, it's dumb but i rather to be sure, in my environment the ground used by SPI should be link to the ground of the smartcard right?
To answer your previous comments, having my own library isn't a problem. I'm doing my project without the Arduino library, like this i have more registers / options to play with. First I was asking how to compute the baud rate because I wanted to trick my Arduino and send data like if my internal clock was at 1MHz. For Riva: The ISO 7816-3 specifies (at least at begining) that every bit duration is 372 clock pulses for a clock at 1MHz, meaning the OP needs the data bit to hold then change only every 372 clock pulses.
I think If I want to use SPI I'll need some pull up resistors as well in order to have a SPI over a single IO wire + clock + ground. What do you think ?