simavr icon indicating copy to clipboard operation
simavr copied to clipboard

Help with external connection

Open jsmith173 opened this issue 3 years ago • 7 comments

Hi,

I'm trying to use simavr in an external gui. My problem with the external connections. For example: pin change interrupts. How simavr should be notified when an input changes? Which data structure should I update?

jsmith173 avatar Mar 17 '21 15:03 jsmith173

I recently did something similar and found the current manual to be less than ideal. I wrote up what I learned as a "Getting Started" guide and I would be interested to know if you find it useful. Here, in my fork.

gatk555 avatar Mar 17 '21 18:03 gatk555

Thanks for the help file.

Now I'm studying the UART. I'm looking for how(where in the code) the TX pin is changing when UART communication in progress. I'm logged the avr_raise_irq with timestamp but I didn't found. TX pin is not changing in the UART communication?

jsmith173 avatar Mar 31 '21 12:03 jsmith173

My impression is that none of the communication peripherals are implemented at the "hardware" level: they do not change or read I/O pins. I think they just simulate the internal behaviour of the peripheral to firmware and provide IRQs to get the data in and out as bytes. That is what I meant by this in my document: "The serial communication periperals (UART, SPI, TWI) are different, as transmissions do not modify pin state and reception does not examine it. Instead, each peripheral has its own IRQs to send and recieve bytes."

I have not looked at those parts of simavr much, as my interest is in simulating firmware for control of analogue circuits.

On Wed, 31 Mar 2021 at 13:59, jsmith173 @.***> wrote:

Thanks for the help file.

Now I'm studying the UART. I'm looking for how(where in the code) the TX pin is changing when UART communication in progress. I'm logged the avr_raise_irq with timestamp but I didn't found. TX pin is not changing in the UART communication?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/buserror/simavr/issues/437#issuecomment-811047626, or unsubscribe https://github.com/notifications/unsubscribe-auth/APAYEBDMFTADMJ3BNLQJWI3TGMMB3ANCNFSM4ZKY6MKQ .

gatk555 avatar Apr 01 '21 09:04 gatk555

But this behaviour can change easily. Or not? Anyway it means currently can't connect an external uart receiver.

jsmith173 avatar Apr 01 '21 15:04 jsmith173

I think that the simulation of communication peripherals to the pin level was seen as being a low priority. So long as you are free to simulate the other end of the circuit in simavr's style it does not get you much, and simply calling avr_connect_irq() as is done in the examples is much, much simpler. But if you want to use a pre-existing UART simulation it becomes important.

My guess is that it would be about 150 lines of code to implement the UART pins. There are files avr_bitbang.* that look like an attempt to do pin-level SPI and they might be a partial model. That code seems not used anywhere, perhaps because it is incomplete.

gatk555 avatar Apr 01 '21 17:04 gatk555

Not only what @gatk555 says, but it would also slow down the simulation by a huge amount to try to actally keep all the pins in the state the hardware does, for very little gain. The peripherals outputs the "logical" interesting things out of the peripherals (bytes out of SPI, uart, i2c etc) but I don't see the point in trying to emulate a cycle accurate output pin.

buserror avatar Apr 01 '21 18:04 buserror

@jsmith173 iIf your goal is to test Arduino codes using simavr for serial communication, it is better to use PICSimLab directly.

Support for Arduino and interfaces with serial signal io (SPI, I2C and UART) are not objectives of the simavr project. PICSimLab uses a modified version of simavr, with support for I2C and SPI signals (master mode only) and Arduino (These changes would never be accepted in a pull request ). The uart signal generation part is in the PICSimLab code itself. It will serve as a starting point if your goal is to make a simulator.

Simavr is a great simulator, and i understand @buserror 's reasons for not adding detailed support to peripherals.

lcgamboa avatar Apr 05 '21 11:04 lcgamboa