Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Orunmila last won the day on December 17 2020

Orunmila had the most liked content!

Community Reputation

51 Excellent

About Orunmila

  • Rank

Recent Profile Visitors

2,461 profile views
  1. I have also catalogued a number of typical I2C errors including typical addressing errors in this blog post
  2. Perhaps I can explain it better with an example. If you wrote code like this, which is using a non-compound literal int i = 7; where do you expect the 7 to be located in the map file? Of course the correct answer is that it gets encoded as part of the assignment code, so it would end up in the TEXT segment with the other code, but there is no rule for this, if this is an auto variable it will just be in the TEXT segment, if it was statically allocated though the compiler may, as an optimization, copy variables in bulk into the ram location of i, but I would say even in that case it goes in TEXT. The problem is not whether or not the literal is valid C or not, of course it is valid, but I think your expectations of where (or perhaps more accurately IF) memory is allocated for the struct are not quite right. I think if you look at the ASM generated for your initializer it will make more sense. In the Microchip PIC's I spent a lot of time on your initializer would compile to something like this MOVLW 2; MOVWF actualCat MOVLW 17; MOVWF actualCat+4 Now if you have code that takes the address of that, it will actually return the address of what? Perhaps the instruction MOVLW? This is dangerous because it will not necessarily behave the way that you expect. If you do a cast like you are doing, depending on the implementation in the compiler it may create a temporary variable on the stack, and then return the address of this temporary variable. This is also dangerous because although your allocation will work the pointer will not be valid later in the application, and even if you test it and the memory is still intact it may be deemed fair game to the compiler to hand out to someone else at the time, in that case it is dangerous as you are pointing to unallocated memory and will get undefined behavior (even in C++). Yes of course I am also using designated initializers in the examples in the article above, I agree that they work great (not only on small devices, on all devices), but of course you lose control of the memory allocation if you do it the way you are doing it (specifically casting the anonymous struct and then taking it's address) because if you start casting things you better know what you are doing because casting == telling the compiler you know better than the compiler - never a great idea 😉 I generally avoid designated initializers though since it was only added in C99 and many compilers from embedded vendors do not yet support them so I always run into portability problems when I do that.
  3. You are initializing the structure using an anonymous structure which is not specified to be located in a specific setion. I have not investigated it any further but I think it might actually be dangerous to take the pointer of an anonymous struct like that because I believe it will be allocated on the stack and it will not be obvious when the memory is being freed (although I may be mistaken here, it still looks dangerous to me). I think what you should do is something like this #define BOB_SECTION __attribute__((section(".bob"))) #define FRANK_SECTION __attribute__((section(".frank"))) struct Cat { uint16_t heads; uint16_t tails; }; FRANK_SECTION struct Cat actualCat = { .heads = 2, .tails = 17 }; BOB_SECTION struct Cat* gNeelix = &actualCat;
  4. I would also suggest you take a look at this because you seem to be writing to the port register bits which will cause read/modify/write errors. Is it possible that the pin is actually toggling really fast?
  5. When that happens it usually indicates something wrong with the connection to the device. The strengths of the pin drivers are not the same on the different programmers. Perhaps you have marginal amounts of capacitance on the lines?
  6. I was not able to create a satisfactory workaround on the A1 or A3 Silicon. We were able to get Rev B2 Silicon which resolves the problem. The official workaround on A1 silicon is not to use the peripheral but instead to bit-bang the I2C. From the Errata:
  7. Thanks for pointing out the mistake, I have updated the post to show 2.0 LSB which is the correct Offset error for this device
  8. Orunmila


    If you load that project it should load with the working version.
  9. Orunmila


    Here is the project I generated, sorry for the random name 🙂 wdqwd.zip
  10. Orunmila


    I tested it and from v1.80.0 of the PIC10/12/16 library onwards this seems to be broken. If you open the "Versions" tab and find the previous version it still works fine. You can switch to the old version in the IDE. It looks like this on my machine. Right-click on the 1.78.1 version and select Mark library for load and then press the load button at the top next to where it says "Versions" it will appear. After doing this I bet it will work just fine. It builds. I will attach the project for you also.
  11. Orunmila


    Sounds like a bug in the latest MCC, have you tried an older version?
  12. I had a similar choice on the CO2 valve for my fishtank, but if my sw had any glitch the tank would be carbonated like soda and everything would die from the ph drop, so I decided to leave the mechanical regulator in the line for a backup if the electronics fail for some reason. You never know what happens when the power goes out or a battery dies at the wrong time...
  13. I used to do a fair amount of optimization using linear programming, it was a bit of a pain to code up so I had hoped this would make that easier ...
  • Create New...