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

Compatibility issue with STM32 F030CCTx #121

Open
kramzarales opened this issue Sep 26, 2022 · 0 comments
Open

Compatibility issue with STM32 F030CCTx #121

kramzarales opened this issue Sep 26, 2022 · 0 comments

Comments

@kramzarales
Copy link

kramzarales commented Sep 26, 2022

Description

The folowing code is meant to read data from a DS18B20 temperature sensor. I upload it to a custom board that has a STM32 F030CCT8 chip on it

When i compile it for the STM32 F030C8Tx (bluepill) it compiles without errors and the code works without issues.

When i compile it for the F030CCTx board (the correct hardwere) it also compiles and runs without errors, but it does not recieve data from the sensor (or can not interpret the signal corectly). I have checked the pin with an osciloscope and found out there is a PWM signal coming from the board.

Steps To Reproduce Problem

I am using a custom board, but the code and the board works. The issue is only with board compatibility.

Hardware & Software

Board: custom board/breadboard
Arduino IDE version: 1.8.15
Version info & package name: Generic STM32F0 series
Operating system & version: win10
Any other software or hardware?
OneWire sensor DS18B20

Arduino Sketch:

#include <OneWire.h>
#include <HardwareSerial.h>

HardwareSerial Serial_MODBUS_S1(USART1);
OneWire Wire_pin1(PA13);

byte i;
byte present = 0;
byte type_s;
byte data[9];
byte data1[9];
byte data2[9];
int16_t raw;
byte cfg;

byte addr[8];
byte addr2[] = {0x28, 0x50, 0x9F, 0xEB, 0x09, 0x00, 0x00, 0xBB}; //28 B8 1F A9 8 0 0 B4
byte addr1[] = {0x28, 0xB8, 0x1F, 0xA9, 0x08, 0x00, 0x00, 0xB4};

float celsius, fahrenheit;

void read_OneWire_1(){

Serial_MODBUS_S1.print("SENSOR 1 ADDR =");
for( i = 0; i < 8; i++) {
Serial_MODBUS_S1.write(' ');
Serial_MODBUS_S1.print(addr1[i], HEX);

}
Serial_MODBUS_S1.println("");
Serial_MODBUS_S1.print("SENSOR 2 ADDR =");
for( i = 0; i < 8; i++) {
Serial_MODBUS_S1.write(' ');
Serial_MODBUS_S1.print(addr2[i], HEX);

}
Serial_MODBUS_S1.println("");

Wire_pin1.reset();
Wire_pin1.select(addr1);
Wire_pin1.write(0x44, 1);
present = Wire_pin1.reset();
Wire_pin1.select(addr1);
Wire_pin1.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) data[i] = Wire_pin1.read();

raw = 0;
raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) { raw = (raw & 0xFFF0) + 12 - data[6]; }
} else {
cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
}
celsius = (float)raw / 16.0;

Serial_MODBUS_S1.print(" Temperature 1= ");
Serial_MODBUS_S1.println(celsius);
Serial_MODBUS_S1.println("");

Wire_pin1.reset();
Wire_pin1.select(addr2);
Wire_pin1.write(0x44, 1);

present = Wire_pin1.reset();
Wire_pin1.select(addr2);
Wire_pin1.write(0xBE); // Read Scratchpad

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = Wire_pin1.read();
}
raw = 0;
raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) { raw = (raw & 0xFFF0) + 12 - data[6]; }
} else {
cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
}
celsius = (float)raw / 16.0;
Serial_MODBUS_S1.print(" Temperature 2 = ");
Serial_MODBUS_S1.println(celsius);
Serial_MODBUS_S1.println("");

}

void setup(void) {
Serial_MODBUS_S1.begin(9600);
Serial_MODBUS_S1.print("start");
pinMode(PB0, OUTPUT);
}

void loop(void) {
read_OneWire_1();
delay(100);

}

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

1 participant