0
\$\begingroup\$

I am trying to get a 7-segment display to run off of an EFR32MG24 dev kit. I know the problem lies in the code, likely in the hex masks or the indexing.
For troubleshooting, I have tried to adjust the hex mask, though nothing changed in the output, and the same goes for when I tried to change the ports and the AND logic.

#include "em_cmu.h" #include "em_gpio.h" #include "sl_sleeptimer.h" // For dev kit onboard connections see UG524 section 3.4 // For dev kit expansion header pinout see UG524 section 3.6.1 (page 19) // We don't have access on this kit to a single bank of pins all on one port // Therefore, we must keep careful track of which pin is attached to each segment // use gpioPortC (2) 0-5 then gpioPortA (0) 5-6 // A B C D E F G . const uint8_t segment_ports[] = {2, 2, 2, 2, 2, 0, 0, 0}; const uint8_t segment_pins[] = {1, 2, 3, 4, 5, 5, 6, 7}; // Hex-formatted masks representing which segments to turn on to display a given number // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F const uint8_t segments[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7b,0x58,0x5e,0x79,0xf1}; // step 1 in instructions int main(void) { // Enable the GPIO clock CMU->CLKEN0 |= 0x1 << 26; // setup 7 segment ports and pins as outputs for (int i = 0; i < 8; i++) { // set pin mode of segment pin to push-pull GPIO->P[segment_ports[i]].MODEL |= 0x4 << (4 * segment_pins[i]); } uint8_t display_number = 0x3f; // some arbitrary number while (1) { // loop through all segments for (int i = 0; i < 8; i++) { // if the segment should be on for the given number if ((segments[display_number] >> i)&1) { // turn on the segment's pin GPIO->P_SET[segment_ports[i]].DOUT |= 1 << segment_pins[i]; sl_sleeptimer_delay_millisecond(10); } else { // turn off the segment's pin GPIO->P_CLR[segment_ports[i]].DOUT |= 1 << segment_pins[i]; } } } } 

Edit: Issue has been resolved, sleeptimer needed to be moved to after the else loop, and a line in the for loop that sets pin mode, to reset them. As the segments were not resetting, only the first segment to light up in a given array would turn on. Below is the updated code for anyone with similar issues in the fuiture:

#include "em_cmu.h" #include "em_gpio.h" #include "sl_sleeptimer.h" // For dev kit onboard connections see UG524 section 3.4 // For dev kit expansion header pinout see UG524 section 3.6.1 (page 19) // We don't have access on this kit to a single bank of pins all on one port // Therefore, we must keep careful track of which pin is attached to each segment // use gpioPortC (2) 0-5 then gpioPortA (0) 5-6 // A B C D E F G . const uint8_t segment_ports[] ={ 2, 2, 2, 2, 2, 0, 0, 0 }; const uint8_t segment_pins[] = { 1, 2, 3, 4, 5, 5, 6, 7 }; // Hex-formatted masks representing which segments to turn on to display a given number // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F const uint8_t segments[16] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7b, 0x58, 0x5e, 0x79, 0xf1 }; // step 1 in instructions int main (void) { // Enable the GPIO clock CMU->CLKEN0 |= 0x1 << 26; // setup 7 segment ports and pins as outputs for (int i = 0; i < 8; i++) { // set pin mode of segment pin to push-pull GPIO->P[segment_ports[i]].MODEL &= ~(0xf << (4 * segment_pins[i])); GPIO->P[segment_ports[i]].MODEL |= 0x4 << (4 * segment_pins[i]); } uint8_t display_number = 0x09; // some arbitrary number while (1) { // loop through all segments for (int i = 0; i < 8; i++) { // if the segment should be on for the given number if ((segments[display_number] >> i) & 1) { // turn on the segment's pin GPIO->P_SET[segment_ports[i]].DOUT = 1 << segment_pins[i]; } else { // turn off the segment's pin GPIO->P_CLR[segment_ports[i]].DOUT = 1 << segment_pins[i]; } } sl_sleeptimer_delay_millisecond (1000); } } 
\$\endgroup\$
5
  • \$\begingroup\$ So, your first attempt at producing code didn't work i.e. you hit a bump in the road so, what did you do to try and resolve this by yourself? \$\endgroup\$ Commented Feb 2 at 15:17
  • 1
    \$\begingroup\$ Please add to the body of your question: did or didn't you test to just put out a constant to light each and every segment? Result? \$\endgroup\$ Commented Feb 2 at 19:25
  • 1
    \$\begingroup\$ Kuro, If you drill into here, down into the Table of Contents by Hardware Driver Class section, you will see a 7-segment driver example for two digits. Have you referenced the code provided there? \$\endgroup\$ Commented Feb 2 at 19:31
  • \$\begingroup\$ Noticeably, there is a delay after using P_SET and none with P_CLR. \$\endgroup\$ Commented Feb 2 at 19:39
  • 1
    \$\begingroup\$ To indicate the question has a known answer, please don't edit it into the question: Answer your own question. (There will be two days before you can accept a self-answer.) \$\endgroup\$ Commented Feb 3 at 6:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.