Jump to content
 

All Activity

This stream auto-updates     

  1. Earlier
  2. I think the list will complete with books on networking protocols. TCP/IP Illustrated, Volume 1 by W. Richard Stevens I found this to be one of the best books to understand how Internet protocols work. I have read the first edition, have not read the second one. Companion book on Unix socket programming, I like the first edition which is very concise, but expects a lot of Unix background. Unix Network Programming, First Edition by W. Richard Stevens Or subsequent edition, if you want more explanation, equally good. Unix Network Programming, Volume 1
  3. 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.
  4. Hi Orunmila. Thank you for the quick reply. The initialization is using something called 'Compound Literals'. It's perfectly valid according to the GCC documentation, but beware, it can be 'dangerous' if you're using C++ (I'm not). Unfortunately, the GCC documentation does not seem to mention how to ensure the compound literals to be in a specific section. -But if anyone would know these things (apart from the compiler developers), it would be developers of embedded software like you. ;) Here's a link to an example, which you may find useful, because initializing this way is really beneficial on small devices: http://nickdesaulniers.github.io/blog/2013/07/25/designated-initialization-with-pointers-in-c/
  5. 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;
  6. I have a pointer to a structure and would like to initialize this to point to a structure. The pointer itself should reside in one section, while the structure's data should reside in a different section. The following example puts the pointer in section '.bob', but how do I ensure the structure data is inside section '.frank' ? #define BOB_SECTION __attribute__((section(".bob"))) #define FRANK_SECTION __attribute__((section(".frank"))) struct Cat { uint16_t heads; uint16_t tails; }; BOB_SECTION struct Cat *gNeelix = &((struct Cat){ .heads = 2, .tails = 17 }); -I've tried placing FRANK_SECTION in every place I could think of on the right hand side of the assignment, but I have not succeeded finding a way to get this to happen. What I'm trying to accomplish would be something like the following, but as a pure initializer: FRANK_SECTION static struct Cat sNeelix = { .heads = 2, .tails = 17 }; BOB_SECTION struct Cat *gNeelix = &sNeelix; Am I so lucky that you have any pointers ? :)
  7. This really is a nice little program to confirm operation of the xpress board! I forgot to check the stdio redirect option in for the eusart module in MCC and so was stuck for a couple minutes! One question is with regard to how the uC is programmed. Does the program go into ram on the xpress board? I have not looked in depth yet, but the program seems to go away when the board restarts. Keith
  8. I followed your instructions step by step. Finally, downloaded SimulatorUART.zip to run. You say "If you run this code in the simulator it will open an additional output window which will show the output from the UART as follows", but my screen doesn't prompt out "UART 1 output" window. So I still cannot see printf() result. My MPLAB X IDE version is 5.35, XC8 is 2.20. And I don't install CCS C Compiler in MPLAB X IDE plugin. Could you help me to figure out my problem. Thank you!
  9. 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?
  10. Hi! I'm not sure that's happening, maybe we can find this together. First, check out this thread about PORT and LAT: If you like to set an output, use LAT registers instead of PORT. Second thing is your code: Is it your intention that variable c is going negative? if (PORTAbits.RA1 == 0) { if (c1_m1 == 1) { c--; c1_m1 = 0; } } You used an "int" type, which means c is a signed 16 bit integer. You could use more explicit types like "int16_t" and check if your code regards the negative case properly. Third thing I noticed: Your while() loop is running with maximum speed. It may be better to have a timing in your main sequence to get a more predictable runtime. For example, just add Timer0 to your main loop: // configure TMR0 according to datasheet, section 20.2 OPTION_REG = 0b11010011; while(1) { // wait here for next cycle while(INTCONbits.TMR0IF == 0); INTCONbits.TMR0IF = 0; // execute cyclic code // ... } About your floating output: How did you measure this? If you have used a multimeter, you likely are measuring the RMS value of a rapidly changing digital output. The TMR0 helps you getting a deterministic behavior, a scope helps you seeing what is really going on... And did you halt the code at certain points and observed the behavior of your pins? With a PICKit or any other debugger attached to your controller, just run a debug session and set a breakpoint where you expect bad things to happen 🙂
  11. Hey guys, I am developing a project with the PIC16F1826 and one of my outputs is flotoating like 1.9V, 2.9V and I can´t find why. I already check the ANSEL registers and initialize the PORTs at 0. It start´s when I add more if statements in my checkmodule() function... Here is the code: int c=0; int c1_m1 = 0; int c1_m2 = 0; int c1_m3 = 0; void main(){ OSCCON = 0b01110000; ANSELA = 0b00000000; ANSELB = 0b00000000; TRISA=0b11111111; PORTA = 0b00000000; TRISB=0b00000000; PORTB = 0b00000000; while(1){ checkmodules(); module_status(); } } void checkmodules(){ if(PORTAbits.RA1==1){ if(c1_m1==0){ c++; c1_m1=1; } } if(PORTAbits.RA1 == 0){ if(c1_m1 == 1){ c--; c1_m1 = 0; } } // When I add mores of this if´s, I start to have the problem with my PORTB outputs... } // end checkmodules() void module_status(){ if(c>0 && c<=3){ PORTBbits.RB4 = 1; } if(c==0){ PORTBbits.RB4 = 0; } if(c>=3){ PORTBbits.RB5 = 1; } if(c<3){ PORTBbits.RB5 = 0; } }// end module_status()
  12. Please check VDD voltage, this dsPIC needs at least 4.5V to do a bulk erase. If it's lower, erasing step will fail.
  13. 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?
  14. I am trying to program dspic30f with pickit4 and using MPLAB X IDE 5.40, on programming it shows Erasing...Verify failed. [config mem] 0x2007, expected 0x1ff, got 0x44Programming did not complete. but it's ok if i use pickit2 to programing
  15. 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:
  16. This is a user help forum for all topics on engineering and embedded software development. Feel free to browse the articles, ask questions and enjoy the fellowship of fellow embedded engineers. Welcome to the group.
  17. How do i start here and what to do ?/
  18. Hi, I am also getting the same problem . I2C is randomly hanging in checking for IDLE state and i checked for flags where ACKEN =1. So i applied reset sequence(9 clock pulses) and bus become IDLE. Now the problem is after some time , Read Time Out errors is coming i.e RBF = 0. I2C Receive buffer(I2C3RCV) is not filled completely. Even i reset with a relay the I2C master is still in the same state. what to do to get out from this problem? Please help.. Controller: PIC32MZ1024EFH144 IDE: MPLABX IDE v5.10 Silicon Version: A1
  19. 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
  20. Thank you so much for this helpful document. In the offset error section; you first say the offset error is 2.5 LSB but then you mention it as 0.5 LSB typical and 2.0 LBS at max. This made me confused a little bit
  21. This is a quick note to warn everyone using the SAMD21 in an Arduino environment with the STL. I use C++ all the time and much of the power comes from using the STL. Vector, queue. array, etc are all canned, powerful libraries that make your life easier. However, the Arduino runtime environment for the SAMD21 conflicts with these libraries. Here is a quick example: #include <Arduino.h> #include <vector> using namespace std; vector<int> count; void setup() { Serial.begin(115200); count.push_back(0); } void loop() { Serial.println("Hello"); delay(500); } A trivial use of a vector to burn up all the RAM. Simply including the vector causes a conflict with the implementation of min(a,b) Building in release mode Compiling .pio/build/mkrzero/src/main.cpp.o In file included from /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/vector:60:0, from src/main.cpp:3: /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2 min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2 max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ In file included from src/main.cpp:2:0: /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected unqualified-id before 'const' min(const _Tp& __a, const _Tp& __b) ^ /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected ')' before 'const' /Users/joejulicher/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected ')' before 'const' The implementation of min for Arduino conflicts with the implementation for the STL. I have done this same build with ESP32 and STM32 and did not have these conflicts. Therefore these are SAMD21 "features". Fortunately you can easily work-around the issue by reversing the include order. Put vector (or other STL's) before the Arduino.h and it compiles just fine. Of course I have not exhaustively tested this combination so your milage may vary. Good Luck
  1. Load more activity
 


  • Popular Contributors

    Nobody has received reputation this week.

  • Who's Online (See full list)

    There are no registered users currently online

  • Forum Statistics

    • Total Topics
      81
    • Total Posts
      376
×
×
  • Create New...