-
Set
HSE
toCrystal/Ceramic Resonator
and disableLSE
as shown -
Set serial mode to
Asynchronous
for bothUSART1
andUSART2
and ensuregloabl interrupt
is enabled underNVIC Settings
-
See below clock configuration.
- Toggle
PLL
andPLLCLK
- Set input frequency to
8Mhz
- Toggle
-
You might want to set the multiplier
PLLMul
to 11 or above then clickResolve Clock Issues
SAVE AND GENERATE PROJECT
- Inside ./Core/Inc/main.h ensure you have chaged the MQTT-Specific settings with yoiur Africa's Talking Device Group and Password
#define MQTT_USERNAME "<Africa's Talking app username>"
#define MQTT_DEVICE_GROUP "<User Device Group>"
#define MQTT_PASSWORD "<Device Group Password>" // Mandatory field
#define AUTH_CREDENTIALS MQTT_USERNAME ":" MQTT_DEVICE_GROUP // Mandatory field;
resolves to username:devicegroup
#define MQTT_QOS 1 // Can be 0 or 1 or 2
#define DEVICE_ID "<Chosen Client ID>" // Mandatory Field
- Note that you can add new subscription callbacks or modifiy the subscription callback to do something else. See ./Core/Src/main.c
void downStreamCommandHandler(MessageData *messageData)
{
serialPrint("Received a message %s : \r\n", messageData->message->payload);
serialPrint("Topic is %s \r\n", messageData->topicName);
memset((char *)messageData->message->payload, '\0', sizeof(uint8_t));
memset((char *)messageData->topicName, '\0', sizeof(uint8_t));
serialPrint("Sending message \r\n");
char dataMessage[100];
mqttMessage.dup = 0;
mqttMessage.qos = MQTT_QOS;
mqttMessage.id = 0;
mqttMessage.retained = 0;
mqttMessage.payload = dataMessage;
sprintf(dataMessage, "test");
mqttMessage.payloadlen = strlen((char *)mqttMessage.payload) + 1;
if (MQTTPublish(&mqttClient, (char *)DEVICE_UPSTREAM_TOPIC, &mqttMessage) == 0)
{
serialPrint("Message published \r\n");
}
else
{
serialPrint("Unable to publish message \r\n");
sent_failed_count++;
}
}
-
See the APN configuration inside
./Core/Src/main.c
-
Note that the line shown below is commented under
./Core/Src/syscalls.c
extern int __io_putchar(int ch) __attribute__((weak));
-
Also note that an IRQ handler is required for USART1; see
./Core/Src/stm32f1xx_it.c
. -
Note the differences under
./Core/{*}/usart.{*}