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

Is 'STM32F103C8' 'digitalWrite' and 'digitalRead' possible in FAST mode? #927

Open
SeongJongKwak opened this issue May 17, 2024 · 10 comments

Comments

@SeongJongKwak
Copy link

Is 'STM32F103C8' 'digitalWrite' and 'digitalRead' possible in FAST mode?

[Same article, forum]
https://www.stm32duino.com/viewtopic.php?t=2401

hello.
[Status]

  1. MCU: STM32F103C8
  2. CORE1: https://github.com/rogerclarkmelbourne/Arduino_STM32

In the case of Arduino (AVR), there are the following libraries.
https://www.arduinolibraries.info/libra ... write-fast
'digitalWrite' Operates 'digitalRead' quickly.

Is it possible to operate ‘Fast mode’ through ‘CORE1’?
If anyone knows, please help.

@board707
Copy link
Contributor

board707 commented May 17, 2024

Is it possible to operate ‘Fast mode’ through ‘CORE1’?

Hi
You can easily write such "fast mode" itself, using the direct port manipulation:

int pin = PA5;
// generate a port and mask for defined pin
uint32_t* pin_set_register = portSetRegister(pin);
uint32_t pin_set_mask = digitalPinToBitMask(pin);

// set pin HIGH  ( as digitalWrite() HIGH)
*pin_set_register = pin_set_mask;

// set pin LOW (digitalWrite() LOW)
*pin_set_register = pin_set_mask << 16;

@SeongJongKwak
Copy link
Author

@board707

Thank you.
I understand how to do it.

Is there a method using 'digitalRead'?

@board707
Copy link
Contributor

I think that the syntax seems to be the similar, but I never need a "fast" digitalRead() in my projects.

@stevstrong
Copy link
Collaborator

stevstrong commented May 17, 2024

use:

uint16_t value = *portInputRegister(pin) & digitalPinToBitMask(pin);

if value == 0 then pin is "low", otherwise pin is "high".

@SeongJongKwak
Copy link
Author

SeongJongKwak commented May 17, 2024

@stevstrong
Thank you for answer.
However, I'm saying this because I don't know much, but 'an error occurs during compilation'.

code :
int pin7 = PA5;
uint16_t value1 = *portInputRegister(pin7)& digitalPinToBitMask(pin7);

error :
\generic_stm32f103c/variant.h:7:44: error: base operand of '->' is not a pointer
#define portInputRegister(port) ( &(port->regs->IDR) )

@stevstrong
Copy link
Collaborator

then try:

uint16_t value1 = portInputRegister(pin7) & digitalPinToBitMask(pin7);

@SeongJongKwak
Copy link
Author

code :
uint16_t value1 = *portInputRegister(digitalPinToPort(pin7)) & digitalPinToBitMask(pin7);

Thank you.

@SeongJongKwak
Copy link
Author

@stevstrong

It doesn't work.

code:
const int SIG[] = {PA5, PA4, PA0, PA15};
//------------------------------------------------ --------------------//
value1 = *portInputRegister(digitalPinToPort(SIG[0])) & digitalPinToBitMask(SIG[0]);
value2 = *portInputRegister(digitalPinToPort(SIG[1])) & digitalPinToBitMask(SIG[1]);
value3 = *portInputRegister(digitalPinToPort(SIG[2])) & digitalPinToBitMask(SIG[2]);
uint16_t hall_y = 0; uint16_t hall_b = 0; uint16_t hall_g = 0;
if(value1==0){ hall_y = 0; }else{ hall_y = 1; }
if(value2==0){ hall_b = 0; }else{ hall_b = 1; }
if(value3==0){ hall_g = 0; }else{ hall_g = 1; }
//------------------------------------------------ --------------------//

@stevstrong
Copy link
Collaborator

What exactly do you mean "it doesn't work"? Which part does not work?

@board707
Copy link
Contributor

board707 commented May 17, 2024

It doesn't work.

@SeongJongKwak
The port access syntax is correct, the error somewhere else in your code.

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

No branches or pull requests

3 participants