I'm trying to communicate with Raspberry pi 3B+ from PIC device via I2C.
My PIC device is PIC16F18325.
First, I generated i2c library by using MCC (mplab code configuration).
raspberry pi is set master, pic device is set slave.
Question
I want to pass data from slave to master, but I don't know how to use the generated library.
How should I use the i2c1_slave.h library in main.c?
My code is here.
main.c
generated libraries from MCC
I2C is a bi-directional bus with at least one master and one slave. Your program on the Raspberry Pi should provide I2C master functions, and the program on the PIC slave functions. The I2C master always initiates data exchanges.
To exchange data with the slave the master sends a byte containing the slave’s address and whether it is going to send more bytes or wait to receive. When the slave receives that byte it should respond accordingly by sending or receiving.
Only when the master (RPi) puts a byte on the bus following an I2C start condition that contains the slave’s address, will an interrupt be triggered on the slave (PIC).
The interrupt service routine must process the received byte and prepare for the next. The read/write bit determines the response and next action, along with housekeeping to prepare for the next interrupt. The exact steps performed by the slave must match what the master expects and vice-versa.
Related
I want to give signal via PLC to Raspberry Pi and when the raspberry pi gets that signal, it should run the python script and when the python script execute properly and cycle is completed, it should wait for the other signal from PLC to again run the same script and same cycle should go on.
Please provide some suggestions.
Via Network:
Depending on your PLC, you could use UDP or TCP, where a Python program on Raspberry listens and sends commands. Depending on the command received, different scripts ou actions could be executed. There are many Python examples for using this on the internet.
For the PLC it can be a little more complicated to find and it will depend on the model and manufacturer, I recommend that you check your supplier's documentation.
Discrete Inputs:
I don't recommend it, but if it's impossible to use a network, you could use discrete digital inputs (like buttons do) to trigger the scripts on the Raspberry, but it must have an interface with relays or optocouplers between the PLC and the Raspberry due to differences in types of electrical signals. In this mode, scripty in pyton keeps checking the status of a digital input and triggers the action when the status of the input changes.
Note:
Note that in both cases the program remains running (in an infinite loop), waiting for the command.
Additional care must be taken when using the Raspberry in an industrial environment due to possible interference by EMC. If using digital inputs, consider applying filters to the signal and shilded cables.
Im planning to create an android Raspberry Pi 3 using Lineage OS. My concern is the GSM module. Does Lineage OS can read the GSM Module (SIM900) in Raspberry Pi and detects it as a SIM Card? My goal is to send SMS using Lineage OS Raspberry Pi 3.
The high level view
connect the SIM900 module to the RPi using the serial connection
write a program to send AT commands to the SIM900 to send SMSes
setup a php script in a web server to receive SMS parameters and make it call the program from step 2.
Lower level view
You may want to read this blog to see how to connect your SOM900 to the RPi. There are actually many blogs like this one so if this one is not clear, just Google "Connecting SIM900 Raspberry"
To send SMS you need to send some so called Hayes AT commands to the modem. The Commands are defined in specification "3GPP TS 27.005", but basically you need to do the following (not tested...). This is adapted Python: I don't know the equivalent of serial module in php:
import serial
import time
modem=serial.Serial("/dev/<the serial device>", baudrate=9600, timeout=1.0)
modem.open()
modem.write("AT+CMGF=1\r")
time.sleep(0.5)
modem.write("AT+CMGS=\"<the desination mobile number>\"")
modem.write(";\r")
time.sleep(0.5)
modem.write(<the content of the SMS>")
time.sleep(0.2)
modem.write(chr(26)) # character Ctrl-Z meaning end of message
time.sleep(0.5)
However, if you want to send messages in a specific charset different from the default GSM alphabet, you'll need to need to do some coding (see here).
I believe the Web Server step shouldn't be an issue for you. You need 2 parameters for your script: the destination of the message and the message itself.
Hope this helps.
I’m really new on the coding world and I need your help. I need to do the following:
In a Zedboard platform I take data from a USB port and want to make real time packets and send them via TCP.
I have establish FreeRTOS for that. I take the data from a UART and keep them in a cycle buffer. I send a TCP command from Matlab for starting the transmission but that gives me just one packet of data. How a make this real time?
I'm afraid I don't understand your question - you mention both USB and UART - is the USB a virtual COM port? Whether its a UART of a USB port, once the received data is placed in the buffer you can use something like a direct to task notification to unblock a higher priority task to then send that data over the TCP link.
There is a FreeRTOS/Zynq/TCP example on the following link: http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCPIP_FAT_Examples_Xilinx_Zynq.html
I am using MPU6050 onboard a GY-86 module. I also have a DS3231 RTC module. when i searched each data sheet i found that DS3231 and MPU6050 have same i2c address which is 0x68. I have read in the MPU data sheet that if i connect the AD0 pin to 3.3 the the address becomes 0x69. but i can't find any AD0 on my module . i only have vcc-3.3v-SCL-SDA-INTa-FSYNC-DROY
I think i have to change i2c address of mpu6050 or ds3231. so that they won't conflict . how can i change i2c dress of MPU or DS module.
Looking at the GY-86 schematic I found, the AD0 pin is hard grounded on the board. This means that unless you can find a trace on the board to cut (unlikely), there is no way to change the MPU6050 slave address. As far as I can see, the DS2321 cannot change its address either.
This leaves you with a few choices:
Change out on of the devices to a different model with a different address. I expect you really don't want to do this.
If your master device (which you did not specify) has multiple I2C bus controllers, hook each device to a different bus.
Use an I2C multiplexer to put the devices on different "virtual" busses. Here's a module with a 1-8 multiplexer which should do the job (though only a 1-2 is really necessary).
I am using ‘SH72867(Renesas)’ connect with ‘EEPROM(24LC04B)’ . In the customer’s document at ‘address 0xF0 of EEPROM have data 0x5555’, But when I reading from this address always return ‘0xFFFF’ and same with other address.
I can’t write to EEPROM too.
I used I2C sample of Renesas but not run.
Do you have any suggestion about setting up I2C?
Sorry for my bad English and no clear explanation.
Any help apprciated,
Thanks
Verify the common issues:
Data and clock are connected properly.
Pull up resistor on clock and data connected to VCC.
Loop the I2C read request, connect scope and verify that I2C signals are OK. In addition check the ACK bit.
Verify clock is lower then 400kHz.
When using code examples, they usually fit to specific board. Verify that the code example configuration is the same as your board.
Some MCU may have more then one I2C pinout options. The code example might use I2C module that connected to diffrent pins.