Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What address is being sent to? #1

Open
rc3105 opened this issue Dec 5, 2018 · 2 comments
Open

What address is being sent to? #1

rc3105 opened this issue Dec 5, 2018 · 2 comments

Comments

@rc3105
Copy link

rc3105 commented Dec 5, 2018

This is great but there seems to be one thing missing, or at least I'm not seeing it.

switch (WireSim.lastAddress()) {

Lets you test for the incoming request address, but where is the equivalent to determine the incoming address for simple writes?

Seems like that would be needed to emulating multiple devices requiring initialization or any sort of output.

thx

@alexisgaziello
Copy link
Owner

Sorry but I never received any notification on this issue.
Do you still have the problem?

I think you should be able to use get the last address as
switch (WireSim.lastAddress()) {
on the receiveEvent method too. Then you will know to which slave the data is intended to go.
I cannot try it myself since I have no Arduino with me right know but you can try it and let me know about the result. If it does not work I will find a solution.
Cheers

@gregersrygg
Copy link

I noticed the same problem when testing this library. The problem is that TWDR gets overwritten by the time receiveEvent() is called. So in my case WireSim.lastAddress() returned the byte that was written to the slave address instead of the address.

I managed to work around it by modifying twi.c to store the address right after it's received:
This file is located in an Arduino related include folder. On MacOs it's probably ~/Library/Arduino15/packages/arduino/hardware/avr/1.8.1/libraries/Wire/src/utility/twi.c

  • After the line static volatile uint8_t twi_rxBufferIndex;

    volatile int lastAddr = -1;

  • After the line case TW_ST_SLA_ACK:

    lastAddr = TWDR >> 1;

  • After the line case TW_SR_SLA_ACK:

    lastAddr = TWDR >> 1;

Then in my sketch I have extern volatile int lastAddr;. Hacky solution, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants