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

Add pinMode() to sendData() and getButtons() #33

Open
gary7530 opened this issue Feb 27, 2023 · 1 comment
Open

Add pinMode() to sendData() and getButtons() #33

gary7530 opened this issue Feb 27, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@gary7530
Copy link

TM16XX and DS1302 their pin definitions are very similar, so I connect their pins together to do use.
The DS1302 also uses pinMode() to change the GPIO settings, so I recommend adding pinMode() to sendData() to make sure it doesn't cause any problems in use.

void TM16xx::sendData(byte address, byte data)
{
  // Pull-up off
  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, LOW);
  
  sendCommand(TM16XX_CMD_DATA_FIXED);							// use fixed addressing for data
  start();
  send(TM16XX_CMD_ADDRESS | address);						// address command + address
  send(data);
  stop();
}
uint32_t TM1620B::getButtons(void)
{
	// Pull-up off
	pinMode(dataPin, OUTPUT);
	digitalWrite(dataPin, LOW);

	word keys_K2 = 0;
	byte received;

	start();
	send(TM16XX_CMD_DATA_READ); // send read buttons command
	for (int i = 0; i < 3; i++)
	{
		received = receive();
		keys_K2 |= ((((received & _BV(1)) >> 1) | ((received & _BV(4)) >> 3)) << (2 * i));
	}
	stop();
	return (uint32_t)keys_K2;
}
@maxint-rd
Copy link
Owner

Hello @gary7530 , thank you for your suggestion. I know that for I2C it is custom to only drive a pin low when sending data and keep it floating on high impedence when inactive, having pull-up resistors on the databus. For the TM16xx I've seen another implementation doing the same.

I appreciate your suggestion as it allows for wider use of shared pins when combining other libraries. I do have a DS1302 module in my collection, so when I can find some time I will have a look and test your suggestion and assess its impact.
I will keep this issue open and post my finding here.

@maxint-rd maxint-rd self-assigned this Feb 27, 2023
@maxint-rd maxint-rd added the enhancement New feature or request label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants