Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:00:40+00:00 2026-05-28T07:00:40+00:00

I am populating an array with data to be sent on the I2C, my

  • 0

I am populating an array with data to be sent on the I2C, my code below shows what I am doing. To me this looks horrible. Is there a better/neater way that anyone can recommend?

Thanks

#define DS1337_SECONDS_REG              0x00
// Default values used for initialisation
#define DS1337_DEFAULT_SECONDS          0x00
#define DS1337_DEFAULT_MINUTES          0x00
#define DS1337_DEFAULT_HOURS_HR_MODE    0x40
#define DS1337_DEFAULT_DAY              0x00 /* Sun */
#define DS1337_DEFAULT_DATE             0x01
#define DS1337_DEFAULT_MONTH            0x01
#define DS1337_DEFAULT_YEAR             0x0C /* 2012 */
#define DS1337_DEFAULT_ALM1_SECS        0x00
#define DS1337_DEFAULT_ALM1_MINS        0x00
#define DS1337_DEFAULT_ALM1_HRS         0x00
#define DS1337_DEFAULT_ALM1_DAY_DATE    0x00
#define DS1337_DEFAULT_ALM2_MINS        0x00
#define DS1337_DEFAULT_ALM2_HRS         0x00
#define DS1337_DEFAULT_ALM2_DAY_DATE    0x00

extern i2c_err_t i2c_send(const i2c_ch_t channel, const uint8_t data[], const uint32_t length, const i2c_stop_t stop);

rtc_err_t ds1337_init(void)
{
    uint8_t data_to_send[17] = { DS1337_SECONDS_REG,       /* Address of first register */
                             DS1337_DEFAULT_SECONDS, DS1337_DEFAULT_MINUTES, DS1337_DEFAULT_HOURS_HR_MODE,
                             DS1337_DEFAULT_DAY, DS1337_DEFAULT_DATE, DS1337_DEFAULT_MONTH, DS1337_DEFAULT_YEAR,
                             DS1337_DEFAULT_ALM1_SECS, DS1337_DEFAULT_ALM1_MINS, DS1337_DEFAULT_ALM1_HRS, DS1337_DEFAULT_ALM1_DAY_DATE,
                             DS1337_DEFAULT_ALM2_MINS, DS1337_DEFAULT_ALM2_HRS, DS1337_DEFAULT_ALM2_DAY_DATE,
                             DS1337_CTRL_REG_INIT_VAL, /* Turn off the squarewave output pin */
                             DS1337_CLEAR_STATUS_VAL   /* Clear the status registers */
                           };

if (i2c_set_address(DS1337_CHANNEL, DS1337_SPI_ADDRESS) != I2C_NO_ERROR)
     return RTC_I2C_ADDRESS_ERROR;

if (i2c_send(DS1337_CHANNEL, data_to_send, sizeof(data_to_send), STOP_CONDITION) != I2C_NO_ERROR)
    return RTC_I2C_SEND_ERROR;

//enable_interrupts(GLOBAL);

return RTC_NO_ERROR;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:00:40+00:00Added an answer on May 28, 2026 at 7:00 am

    This is a pretty standard approach. Enums (instead of defines) won’t make your source code much shorter. Hardcoding the constants in the code will make it unreadable. Having multiple calls to i2c_send() and no array will be about the same, though probably slightly bigger and less readable. Defining a number of functions to configure every little thing is a sure way to make the source code bigger. I’d probably just keep the code the way it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI, I have code like this. what I am doing is populating the first
There may be a simpler way of doing this and I am all ears
im populating the data in the combo box using dataset tables...with some table name..now
I m populating data for different entities into set of lists using generic lists
I am populating a UITableViewController's UITableView through code only. At the bottom of the
I have the following piece of code. This is written for getting the list
I am populating a set of arrays from worksheet data. I then manipulate the
I am populating an array with instances of a class: BankAccount[] a; . .
I'm populating an array using a method however I receive 2 errors of a
I'm trying to work out the correct way to handle populating an array with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.