MSP430 I2C slave to generate PWM signal , master is R-pi3 - microcontroller

I need to code for a MSP430FR5969 launch pad that can generate PWM signal upto 100KHz, I want to control it with R-Pi3 over the I2C bus to send the Freq and duty cycle to the MSP430.
I am very new in coding MSP430, any help would be appreciate it.
thans

I find the best approach is to look at the examples provided for this particular LaunchPad. You'll now find these under Resource Explorer.
Run the PWM example and get your head around what it's doing. This should be easy enough using the on-board LED.
Then run the I2C example and get your head round what that's doing. You can connect it straight to the Pi, but a logic analyser will really help with this.
Peripheral setup is the hardest part of MSP430 coding. Once you get this right (or just copy it from an example) the code in between is normally much easier.

Related

ESP32 CAM - EEPROM / sdcard / non erasable memory - beginner problem

Overwiew
I am working on my first project with ESP32, I have ESP32 CAM model and I am creating an automatic roller blinds. I got most of the project working - I have web server that controls continous servo and all mechanics. I want to be able to adjust the time for going up-down without reprograming the microcontroller. The goal is to have an automatic roller blinds with alarm clock function.
Problem
I need a way to reliable save/read data to store variables state, even without power. How to achive it with ESP32 CAM?
Additional info
On Arduino board that would be EEPROM, and I found some tutorials that claim that EEPROM can be used on ESP32. However, when I tried using EEPROM, it looks like the values are overwritten while bootloading. So I guess ESP32 CAM needs different approach. Correct me if I am wrong, please.
Ok, so user bvguy on Reddit solved my problem.
"EEPROM is deprecated. They want you to use preferences now. Here is an example ."
I tested the example and it works on my ESP32 CAM, therfore solving the problem.

Putting my raspberry pi program on a more primitive chip

I recently started coding on a raspberry pi. I build a circuit with three buttons, an LED and a 7 digit LCD. Its a fairly simply thing. You can set a time value with the + and - button in seconds and then press the other one to start a countdown. I use this to do triggered long exposures with my camera. However the raspberry pi is to big and bulky and needs to much energy.
Then I put my code and my circuit on an Arduino UNO which is an improvement in size and energy consumption.
Because my program is very simple I am sure that there must be a way to get this on a much smaller chip. I need some kind of programmable chip where I can put my code onto. Something that is small and dont has any other fancy features or more calculating power than I could need. As far as my knowledge goes I dont have any idea how to get into that.
At work we have a 3D printer with a W1209 temperature relay controller on it. This is a small circuit with the same 7 digit LCD pane and the temperature is also settable with two buttons. This inspired me to look for something much more primitive that would be enough for my needs.
Can you recommend any hardware or some tutorials about that?
Search the Microchip website for the DM164141 - MPLABXpress PIC16F18345 Evaluation Board. I think it's around $12 and should have enough I/O for your application. You can use the online MPLABXpress IDE for development.

Why do we need to select a board to work with arduino IDE

I always wondered how this works . In arduino IDE we have option to select different boards because the code upload i guess is different ? Also there is possibility to even add board manager url to add other boards.
Why uploading the code is so different from board to board , and what exactly differs there ? The code is sent to via serial connection and i understand that a board might have different chip for handling USB to serial but ..
Can someone explain as clear as possible , how the code is uploaded to a board and why there is no generic way , why so many configurations.
Thanks and sorry if is a dumb question.
One of the important things that selecting a board does is, as you say, inform the IDE of how to load code onto the board. Perhaps more importantly, the board definitions give you the logical mapping of the board's hardware to the code constructs you are using to program against. For example, have you ever wondered what happens when you use a constant like PIN_13, or how that constant maps to a physical pin on your board, which has a trace to some contact on the microcontroller chip itself?
There is a lot of other code you don't see, much of it in the board definitions (and some in the Arduino core) which lets you work with relatively direct concepts (like pin numbers and modes) in the code that you write or edit.

A way to change mcu program from the outside

We need to change a controller code from the out side as they do with industrial MCU .
So that you have an mcu,with a program on it, and someone can program some "words" to it, that will determine how it works.
So for example you can program an mcu -not with a programer but with some inputs from serial, to do some simple things such as:
if input A==1
b=1
I wonder if there is a smart way to do that with simple software on the mcu, that it has many #defines for various commands, and it perform them according to values it gets from the outside (and saved for the rest of the program).
I wonder if the industrial programers are using that method, or that every programing of a user is actually load a code(.hex) to the chip(with internal programer ) .
I prefer the simplest way(i wonder if its by pre defined software)
A couple of options come to mind so hopefully this answers your question. It sounds like the simplest version of your question is "How do I change the behavior of the MCU without an actual MCU programmer?" A couple of options come to mind.
1) Depending on the MCU you can have a bootloader that is essentially a small piece of code programmed in the MCU by a programmer that has the ability to reprogram other parts of the MCU. This doesn't require a programmer but involves some other form of letting the bootloader know what the new code is (USB, Serial, SD Card, etc). This will only work if the MCU has the ability to self flash.
2) Again, depending on MCU and scenario you could program a generic set of rules that carry out functionality based on the inputs given to the MCU. This could be in the form of IO pins, EEPROM, or a domain-specific script on an SD card that the MCU can read and interpret at runtime.
Both options depend on the MCU you are using and what hardware capabilities you have at your disposal. But you certainly have options other than reprogramming the end hardware with an actual programmer every time you want to make a change. Hopefully that helps.

Communicating with the Pic 16F913

Here is my issue, it appears that all the communication lines for the PIC 16F913 reside on the same set of pins, this is convenient in that I don't have to sacrifice GPIO pins just to do comms, however the problem I'm having now is if I'm using the SPI on the chip, how can I send information to the RS232?
The reason this issue came up, is that I just bought a CAN bus chip that communicates over SPI, and I would really like to see the data on RS232, so I can see messages. (I really don't know much about CAN yet, so who knows if this even makes sense yet).
Here are the options I see, and maybe someone else has better ideas that I'm just simply missing.
Somehow setup a time scheme that will switch between SPI and RS232 every time I get data,
-- This doesn't seem hard and should work, but supposing I don't want to miss a message, what if a message is written while I'm writing to RS232, is it possible I'll miss it?
2.. I can always use SPI, but then build my own comm bus over 8 of the GPIO lines, to another PIC 16F913, using only the GPIO lines and then since the RS232 lines are free on the second PIC I can simply read the data and spit it out.
-- This one is doable but now we're wasting 2 chips, AND all the GPIO lines,
There has to be a better way. Or is there?
Any help is greatly appreciated.
Update: I would like to clarify, obviously one solution is using a completely different chip (which may in fact be what I end up doing, if I can get the 18F programmed), however, I'm interested in worst case scenario, in which I am limited in resources and only have some 913's, is the way described above the only way to do it with this chip, or is there a better way?
You could do a software implementation of the SPI bus - it's easier to do than the UART because the timing isn't critical and you are in control of it.
Most CAN chips have a few receive buffers so if you're busy doing something with the UART then the messages will be buffered inside the CAN chip. But... you will need to make sure that you can get the messages out of the CAN chip fast/often enough so you don't lose some.
You would probably have to either use an interrupt for the UART Tx process - so that you can be receiving CAN messages while you're sending data on the UART.
If you're only interested in certain messages most CAN chips have filters - this makes it easy to only receive the messages you're interested in, usually dropping the number of packets/second dramatically.
You can use a software implementation of a RS232 port. For example the c compiler from http://mikroe.com comes with such a library. But it shouldn't be too hard to shift bits to an output pin, rs232 is a fairly simple protocol.
I strongly recommend that you change the MCU with PIC16F1933.
It is newer
It is cheaper
With EUART and MSSP moduls.
The MCU arhitecture is impruved.
The PIC16F913 MCU will become obsolete in next few years!

Resources